angular-cli: ng build --prod unable to process symbolic links

OS?

Linux Ubuntu

Versions.

@angular/cli: 1.0.0-rc.0 node: 7.4.0 os: linux x64

I am working on two angular-cli projects (frontend and backend). As they share many components, services etc, I created a folder “actual-common” and put a symbolic link “common” under the src folder of each project. This worked well until I performed an ng build using the --prod option, at which point every shared item gives the following message.

ERROR in ../actual-common/modules/auth0/logout/logout.component.ts
Module build failed: TypeError: Cannot read property 'text' of undefined
    at Object.getTokenPosOfNode (/home/Angular/frontend/node_modules/typescript/lib/typescript.js:6768:71)
    at IdentifierObject.TokenOrIdentifierObject.getStart (/home/Angular/frontend/node_modules/typescript/lib/typescript.js:80500:23)
    at IdentifierObject.TokenOrIdentifierObject.getText (/home/Angular/frontend/node_modules/typescript/lib/typescript.js:80521:77)
    at refactor.findAstNodes.filter (/home/Angular/frontend/node_modules/@ngtools/webpack/src/loader.js:139:44)
    at Array.filter (native)
    at refactor.findAstNodes.forEach.node (/home/Angular/frontend/node_modules/@ngtools/webpack/src/loader.js:138:14)
    at Array.forEach (native)
    at _removeDecorators (/home/Angular/frontend/node_modules/@ngtools/webpack/src/loader.js:129:10)
    at Promise.resolve.then (/home/Angular/frontend/node_modules/@ngtools/webpack/src/loader.js:292:33)
 @ ./src/$$_gendir/app/app.module.ngfactory.ts 81:0-79
 @ ./src/main.ts
 @ multi ./src/main.ts

I noted that the error refers to my absolute path “actual-common”, so I presume it is a webpack issue similar to https://github.com/webpack/webpack/issues/1643 I also note that a custom webpack configuration is not available using Angular-Cli, so the workaround described on the issue is not available to me.

My workaround was to clone the project and replace the “common” symlink with the actual files.

(Is there a better way to share code between local projects?)

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 11
  • Comments: 26 (2 by maintainers)

Most upvoted comments

Further to my previous comment, it would appear that we now have a –preserve-symlinks flag available in “ng build” https://github.com/angular/angular-cli/pull/6460

This cured my symbolic link problem with vscode debugging - all my symbolic link problems have been solved, as far as I am concerned this is a closed issue.

ng build --preserve-symlinks --watch, does not allow angular-cli to build my project with symlinked files inside node_modules. My issue is not resolved. I cannot develop locally without npm link.

I’m getting a similar issue on Windows 7 which appears related to routing, but I’m not using symlinks. But I get the error only in IE11, not Chrome. I’m using all the recommended IE polyfills from polyfills.js. Angular 4.0.0, CLI 1.0.0.

I was trying to create a repro but haven’t narrowed it down to something small yet. Again, only get the error with ng serve --prod (or ng build); error goes away with --aot false.

"Uncaught (in promise): TypeError: Unable to get property 'initialNavigation' of undefined or null reference
TypeError: Unable to get property 'initialNavigation' of undefined or null reference
   at t.prototype.isLegacyDisabled (http://localhost:4200/vendor.35a56695c585013b7d07.bundle.js:407:2550)
   at Anonymous function (http://localhost:4200/vendor.35a56695c585013b7d07.bundle.js:407:1510)
   at t.prototype.invoke (http://localhost:4200/polyfills.1b67348a0bf296656461.bundle.js:36:9782)
   at onInvoke (http://localhost:4200/vendor.35a56695c585013b7d07.bundle.js:316:8090)
   at t.prototype.invoke (http://localhost:4200/polyfills.1b67348a0bf296656461.bundle.js:36:9782)
   at n.prototype.run (http://localhost:4200/polyfills.1b67348a0bf296656461.bundle.js:36:5065)
   at Anonymous function (http://localhost:4200/polyfills.1b67348a0bf296656461.bundle.js:36:2119)
   at t.prototype.invokeTask (http://localhost:4200/polyfills.1b67348a0bf296656461.bundle.js:36:10439)
   at onInvokeTask (http://localhost:4200/vendor.35"

As @kipy-be says, symbolic links work with “ng serve”, plus “ng lint” and even “ng build” just as long as you do not use the --prod flag. Both “ng build --prod” and “ng serve --prod” cause the error.

We have made a few changes to how we process symlinks, and think this issue was fixed in one of them. Closing then.

So, Angular + symlink issues add up as following?

  • --aot must be used with --preserve-symblinks
  • But when --aot is on, due to Webpack’s watchpack issue, watch symlink directories might malfunction

@djtahl Sound likes the Assets not working after update issue. Try the following

 ng serve --base-href /

+1 Same on Windows 10 But the symlinks are correctly resolved with “ng serve”