5

I am creating a new Angular project without downloading the dependencies, like: ng new sample-app --skip-install

I have all necessary dependencies in node_modules in a different folder of a different angular app named older-app. I want the newly created sample-app to refer to the node_modules of older-app. How can I achieve this?

2
  • 1
    Why not just copy it to your new project folder? Commented Mar 22, 2018 at 12:35
  • well, few reasons. If I miss something, the app will break. If I have to update, I have to update it in both the places. Also, it is going to hog space as it will be an exact copy of the existing hundreds of dependencies. Commented Mar 22, 2018 at 12:36

2 Answers 2

4

Well, the easiest way is to create a symbolic link in sample-app that points to the other node_modules.

If you're in windows,

cd sample-app
mklink /J node_modules "../older-app/node_modules"

Not sure about syntax in linux or MacOS, but it will be similar.

I don't really recommend this, though, because though updating or adding packages in one directory will affect both (as both node_modules are really the same), only the package.json file of the directory you are in will be modified.

This implies that, if you share the app with another person or put it in another machine, running npm install won't guarantee that you get the same packages, which can cause errors, so do this on your own risk.

For example, if you go to older-app and update Angular to version 6, sample-app will be modified, too. So you can change the code, developing against Angular 6. However, if you then upload that app to Github or other repository, whoever downloads it, when they run npm install will get Angular 5, which is sure to cause errors.

package.json files must always be in sync with the node_modules directory.

Sign up to request clarification or add additional context in comments.

1 Comment

when i created the symbolic link to node_modules folder and executed ng server -o command from the new folder then webpack is still referring to old-app/node_modules/.... modules. what could be the reason?
0

The only real option seems to be, moving the cli file. as to see here:

https://github.com/angular/angular-cli/issues/3864

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.