2

I'm building a new angular app and anywhere I do console.log's it comes from main.js:1 or polyfills.js:1 and not from the proper component. I tried to add main.js and polyfills.js to Ignore list in the dev tools settings but it doesn't work too.

Maybe the problem is that I'm doing ng serve --ssl true? But in this case, I can't even check if it works without this flag. It has to be with ssl. Thanks for any feedback

enter image description here

another example: enter image description here

*EDIT

Also I can say that compiling and recompyling time is very long. Like 20-40second somtimes

Symlis
  • 101
  • 1
  • 8
  • all of your component code gets compiled into main.js and polyfill.js when you serve your app. That's where the site runs from, not your individual component files. What are your trying to do that you want the console logs to come from a specific component? – daddygames Jun 23 '21 at 13:22
  • exactly. If I make a console.log('123') in eq. componentA:44 I'd like it to have this information in the browser console - that there's console.log in the componentA in 44th line. And it's always like this actually (from my experience from different projects), I've never seen this before. – Symlis Jun 23 '21 at 13:37
  • 2
    Please check whether you are doing a production build or dev build. If it is production build console.log will show in main.js file only. If it is a dev build it will show corresponding component with line number. – Ranjith S Jun 23 '21 at 15:41
  • hmm, I guess I'm doing dev build. For example when I do `if (isDevMode()) { console.log('test'); }` it's being displayed in the console but ofc in main.js:1 – Symlis Jun 24 '21 at 09:01
  • Also when I `console.log(environemnt.prod)` it gives me `false`. – Symlis Jun 24 '21 at 09:33

1 Answers1

6

It occuurs that "ng serve" served my app in the prod mode (idk why). I made my own dev mode in the angular.json where I turned off aot and buildOptimizer, optimization, namedChunks, vendorChunk and it works ok (fast compilation time and visible console logs)

Symlis
  • 101
  • 1
  • 8
  • can you share the config? – ScipioAfricanus Dec 31 '21 at 19:50
  • I can't share full config but try to make your own config in angulaj.json, something like: configurations: { "customConfig": { "optimization": false, "outputHashing": "all", "sourceMap": true, "namedChunks": false, "aot": false, "extractLicenses": true, "vendorChunk": false, "buildOptimizer": false } } then start project with: ng serve -c customConfig – Symlis Jan 03 '22 at 13:15
  • thats all I needed! It worked! Thanks!!! – ScipioAfricanus Jan 03 '22 at 19:41
  • I'm glad it helped :) – Symlis Jan 04 '22 at 11:38
  • Hi i have did the same thing but nothing changed , what can i do ? – AkiZukiLenn Oct 05 '22 at 06:23
  • Check your `environement.ts` file if you have `production` flag set to true. If yes then your app is going to serve in production mode. Basically, you need two environment files. One for development and one for production. Angular serves in production mode by default to avoid errors on deployment – Symlis Oct 10 '22 at 14:37