question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bug in angular compiler (ng build) when using npm's link

See original GitHub issue

I’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:closed
  • Created 5 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
trotylcommented, Apr 17, 2018

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.

0reactions
angular-automatic-lock-bot[bot]commented, Sep 13, 2019

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

angular 13 ng build library fails (ivy partial compilation mode)
This solution appears to be for an Angular app. I'm trying to build a library. · 2. This is why i wrote "if...
Read more >
@angular/cli - npm
Start using @angular/cli in your project by running `npm i @angular/cli`. ... Alternatively, you can install npx and run npx ng <command> ...
Read more >
Converting your Angular CLI application into a NPM Module
The first method I used was installing the local package with each build by providing the full path to my local directory. ......
Read more >
How To Update Angular CLI To Latest Version
Just update @angular/core and @angular/cli by using ng update command. ... Then install latest Angular CLI version using npm install -g ...
Read more >
Creating libraries - Angular
Publishing librarieslink ... For publishing to npm use the partial-Ivy format as it is stable between patch versions of Angular. Avoid compiling libraries...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found