Jeff Dege Jeff Dege - 1 year ago 98
AngularJS Question

How do you manage versioning of dependencies, in nodejs?

We've been a Windows shop, mainly relying on Visual Studio as our IDE and build tool. We've begun to explore using Angular and node, and angular-cli.

We have a project that depends upon "angular-cli": "1.0.0-beta.10". I was trying to get this to build on a new machine.

I installed nodejs, then did a global install of angular-cli using npm:

npm install -g angular-cli

Then I tried to do a build:

ng build

I got an error:

It seems like you're using a project generated using an old version of the Angular CLI.
The latest CLI now uses webpack and has a lot of improvements including a simpler
workflow, a faster build, and smaller bundles.

To get more info, including a step-by-step guide to upgrade the CLI, follow this link:

What I did to get things working was to uninstall angular-cli, and then install version beta.10

npm uninstall -g angular-cli
npm install -g angular-cli@1.0.0-beta.10

After that, things work just fine.

Unfortunately, that's not a solution.

We will, eventually, have multiple projects using node packages, we need them to be able to run simultaneously, without having to uninstall and reinstall global packages.

And we need to be able to run builds automatically on our build machines, without having to RDP into the build machines to mess about with which node packages are installed.

That is, if I have three projects that use angular-cli@1.0.0-beta.10, I expect all three to work on any of the developers machines, and that the build machines will be able to check out any of the three projects and successfully build them.

And if I update one to use beta-12, and another to use beta-14, I expect to be able to commit them to version control, and for the build machine to be able to check out any of three and still be able to build them, regardless of which version they use.

I thought the whole idea of tracking local dependencies in package.json, and storing local copies in node_modules was to avoid dependencies on globally installed packages.

How do people usually manage this issue?

Is there a way I can configure angular-cli so it doesn't depend upon a global install?

Are there other packages with which I'm likely to encounter similar problems? Is there an approach that will work for any of them?

Answer Source

The Angular-CLI can be run with, and the global ng command uses, a locally installed version for each project. This local version can be accessed using the command ./node_modules/.bin/ng

I recommend uninstalling the global CLI you have and taking the time to modify your package.json scripts to reference the local CLI installation rather than the global ng. This is my method to handle varied CLIs on my Jenkins server.

On that note, I do highly suggest following the instructions to move from Beta.10 to Beta.14 ( if you can stomach the change to WebPack. Any projects utilizing CLI Beta.14 or higher can be upgraded to Beta.21 simply by uninstalling the CLI, reinstalling it, and then running ng init (Diff [d] any files you've modified!) to update the boilerplate.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download