angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

ng build --prod unable to process symbolic links

Open ghost opened this issue 9 years ago • 26 comments

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?)

ghost avatar Feb 28 '17 09:02 ghost

My ng server command in full is as follows.

ng serve --host 0.0.0.0 --disable-host-check --preserve-symlinks --base-href /

You need to make sure you are running an up to date version of the CLI or at least @angular/[email protected] which is the version that originally worked for me.

ghost avatar Sep 04 '17 13:09 ghost

According to the source file of the serve command (here) there is no --preserve-symlinks for the serve command.

SebastianSchenk avatar Sep 24 '17 13:09 SebastianSchenk

Its handled within the build command (here) . I am not an expert in the details of how ng serve works, but I always assumed ng serve calls ng build and would pass the parameters across?

ghost avatar Sep 24 '17 18:09 ghost

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.

ORESoftware avatar Feb 14 '18 22:02 ORESoftware

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

liujingbreak avatar Nov 06 '18 09:11 liujingbreak

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.