Skip to content

CLI with linked NPM modules #7137

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mattem opened this issue Jul 25, 2017 · 9 comments
Closed

CLI with linked NPM modules #7137

mattem opened this issue Jul 25, 2017 · 9 comments

Comments

@mattem
Copy link

mattem commented Jul 25, 2017

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.

@jevenson
Copy link

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

@jwuliger
Copy link

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.

@mattem
Copy link
Author

mattem commented Jul 27, 2017

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

@jwuliger
Copy link

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

@clydin
Copy link
Member

clydin commented Jul 27, 2017

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.

@jwuliger
Copy link

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!

@mattem
Copy link
Author

mattem commented Jul 29, 2017

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

@mattem
Copy link
Author

mattem commented Jul 29, 2017

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
},

@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants