Angular-cli: CLI with linked NPM modules

Created on 25 Jul 2017  Â·  9Comments  Â·  Source: angular/angular-cli

Bug Report or Feature Request (mark with an x)

- [x] bug report -> please search issues before submitting
- [ ] feature request

Versions.

Matts-MacBook-Pro:Documents matt$ ng --version
    _                      _                 ____ _     ___
   / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
  / â–³ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
 / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
/_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
               |___/
@angular/cli: 1.2.3
node: 7.7.4
os: darwin x64

Repro steps.

Using CLI version 1.0.0 we could successfully use npm link to publish from our src directory (publishing Typescript) between our library project and it's consumer to aid in rapid development.
Following the upgrade to CLI 1.2.3 we are no longer able to build using the linked src directory.

Using 1.0.0 the function _isNgModuleMetadata returns true for modules in the linked source, in 1.2.3 it returns false - leading to the error reported by Angular:

Uncaught Error: Unexpected value '[object Object]' imported by the module 'AppModule'. Please add a @NgModule annotation.

(removing the forRoot on that module makes the correct unexpected value name appear there)

Edit: I've narrowed it down to version 1.0.3 (working) and 1.0.4 (not working)

Desired functionality.

To be able to link to the src of our projects, without having to stay at an older version of CLI. Rebuilding our libaray project on each change is too slow workflow.

Unfortunately this is closed source project, so I can not post the exact source, but I can make a small demo if required given some more time.

Most helpful comment

Please see this guide from the wiki for details on configuration. Note that the last paragraph refers to the app not the linked library.
There is also the --preserve-symlinks option for ng build/ng serve which may also be useful.

All 9 comments

I experience this only when not using AOT. When using the AOT flag on ng serve, the app works as expected.

Hello, all. Just upgraded to 1.3.0-rc.2 and now I am not able to use linked modules myself. One of the linked modules I use is this one lol. So can always be current with the Master branch. Now when I try to use npm link to link my global CLI to my local version it installs everything just fine.

However, when you call ng or 'ng help` for example, I am getting the following error:

PS C:\Windows\system32> ng
undefined:3
<<<<<<< HEAD
^

SyntaxError: Unexpected token < in JSON at position 34
    at JSON.parse (<anonymous>)
    at glob.sync.filter.map.map.reduce (C:\Projects\@angular\angular-cli\lib\packages.js:22:26)
    at Array.reduce (native)
    at Object.<anonymous> (C:\Projects\@angular\angular-cli\lib\packages.js:21:6)
    at Module._compile (module.js:569:30)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
    at Module.require (module.js:513:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (C:\Projects\@angular\angular-cli\lib\bootstrap-local.js:12:29)
    at Module._compile (module.js:569:30)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
    at Module.require (module.js:513:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (C:\Projects\@angular\angular-cli\bin\ng:7:1)
    at Module._compile (module.js:569:30)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
    at Function.Module.runMain (module.js:605:10)
    at startup (bootstrap_node.js:158:16)
    at bootstrap_node.js:575:3

Running Windows 10 Pro
Node: 8.1.4
NPM: 5.3.0

Anyone else running into this? Thanks.

@jevenson I've experienced the same, however switching to AOT for a development workflow is too slow, it takes too long to rebuild our application on each change with AOT.

@jwuliger Your issue seems to be related to having GIT merge conflict markers within the source of ng cli, resolve the conflicts in GIT.

@mattem Thanks for the response. Yeah, my GIT was all messed up. I fixed that and now I am using the latest angular/cli-builds. Now all is right with the world again lol.

Please see this guide from the wiki for details on configuration. Note that the last paragraph refers to the app not the linked library.
There is also the --preserve-symlinks option for ng build/ng serve which may also be useful.

Hi, @clydin, when I do use the master branch to do an NPM Link, I do use the --preserve-symlinks flag in my run script. I was really happy when I saw it come out. Thanks for your help!

@clydin Thanks for the info - our library code already conformed to suggestions in the wiki.
The --preserve-symlinks option worked and I was able to serve and build our application with the source linked. However, the flag does not seem to be supported on ng test. Could this be added? I'd be happy to submit a PR if it's something the team would consider.

After having a dig through the ng cli source, it seems that preserveSymlinks is available when using ng test. It can be added to the angularCli block in karma.conf.js:

angularCli: {
      environment: 'dev',
      preserveSymlinks: true
},

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._

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hareeshav picture hareeshav  Â·  3Comments

ericel picture ericel  Â·  3Comments

brtnshrdr picture brtnshrdr  Â·  3Comments

rwillmer picture rwillmer  Â·  3Comments

rajjejosefsson picture rajjejosefsson  Â·  3Comments