Bug in angular compiler (ng build) when using npm's link
See original GitHub issueI’m submitting a…
[x] Bug report
Current behavior
‘ng build’ gives an incorrect error in scenario detailed below. If I do ‘ng serve --open’ it also fails to compile initially but if I remove a bracket, save and undo + save again in app.module.ts for example then compile will pass and app runs normally. So there seems to be a glitch in ng build the first time it runs, because the second time it works correctly although the contents are identical.
Expected behavior
‘ng build’ should pass as it is just a default new app generated using CLI ‘ng serve’ should work from the start without the workaround described above
Minimal reproduction of the problem with instructions
Environment vars set below make npm packages be installed in a specific ‘global’ location and using the link setting to reuse packages and avoid 300 MB downloaded and installed for each separate app. This way each default CLI new app will use 50-60 KB of disk space instead of ~300 MB each. So for example with those set the cli install would be equivalent to a npm install --link --prefix D:\angularCLI\alternateGlobalNPMRepo -g @angular/cli
command.
To reproduce it run the following commands inside an empty dir (in my case ‘D:\angularCLI’) (I am on windows 10, using cmd):
set npm_config_link=true set npm_config_prefix=D:\angularCLI\alternateGlobalNPMRepo set PATH=%PATH%;%npm_config_prefix%
npm install -g @angular/cli
ng new my-new-app
cd my-new-app
ng build ng serve --open
Both ng build
and ng serve --open
will give an error:
ERROR in No NgModule metadata found for ‘AppModule’.
But if you change something in app.module.ts, save, change it back, save then ng serve
compiles successfully and refreshing the browser will show the app.
What is the motivation / use case for changing the behavior?
Npm link basically creates OS symbolic links in the node_modules folder towards the global npm folder - so I don’t know why ng build fails first time. Please fix this so I don’t have to download and store the same 300 MB multiple times when I don’t need to.
Environment
Angular CLI: 1.7.4
Node: 8.9.4
OS: win32 x64
Angular: 5.2.10
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router
@angular/cli: 1.7.4
typescript: 2.5.3
webpack: error
For Tooling issues:
- NPM version: 5.8.0
- Platform: Windows 10
Issue Analytics
- State:
- Created 5 years ago
- Comments:9 (3 by maintainers)
This is not a problem of Angular compiler (which is
ngc
), you should instead refer to Angular CLI repo; Also please have a look at preserveSymlinks option.This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.