简体   繁体   中英

How can i keep one node_modules folder for multiple Angular projects which has same dependencies?

I like to keep one node_modules for multiple Angular projects since it does not add around 500mb data per project into my HDD - ( yes this question has been asked many times before, i tried almost all tips in them but did not work)

This is my folder structure

:~/Public/node_modules/angular/ <-- this is where contents of usual node_modules folder end up

:~/Public/angular/project1/ <- ng new -skip-install

:~/Public/angular/project2/ <- copy of above and not running above command

and i have modified the usual 2nd line of angular.json to this

"$schema": "../../node_modules/angular/@angular/cli/lib/config/schema.json",

and when i do ng serve

i get the following error

An unhandled exception occurred: Cannot find module '@angular-devkit/build-angular/package.json'
Require stack:
- /usr/local/lib/node_modules/@angular/cli/node_modules/@angular-devkit/architect/node/node-modules-architect-host.js
- /usr/local/lib/node_modules/@angular/cli/node_modules/@angular-devkit/architect/node/index.js
- /usr/local/lib/node_modules/@angular/cli/models/architect-command.js
- /usr/local/lib/node_modules/@angular/cli/commands/serve-impl.js
- /usr/local/lib/node_modules/@angular/cli/node_modules/@angular-devkit/schematics/tools/export-ref.js
- /usr/local/lib/node_modules/@angular/cli/node_modules/@angular-devkit/schematics/tools/index.js
- /usr/local/lib/node_modules/@angular/cli/utilities/json-schema.js
- /usr/local/lib/node_modules/@angular/cli/models/command-runner.js
- /usr/local/lib/node_modules/@angular/cli/lib/cli/index.js
- /usr/local/lib/node_modules/@angular/cli/lib/init.js
- /usr/local/lib/node_modules/@angular/cli/bin/ng
See "/tmp/ng-kyWfPF/angular-errors.log" for further details.

How do i get rid of this and get the functionality i desire of having one node_modules for many projects like i have mentioned above?

If I understood correctly the node_modules and angular are on the same level, so in this case, you set incorrect path in angula.json. You need

"$schema": "./node_modules/angular/@angular/cli/lib/config/schema.json"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM