1

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 ?

R. Richards
  • 24,603
  • 10
  • 64
  • 64
Danushka Gunawardena
  • 1,109
  • 1
  • 9
  • 17

1 Answers1

0

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"
Slava
  • 161
  • 1
  • 5
  • Thanks for the reply - sorry no - they are in same level but, since angular project folders are inside angular folder - you have to go two levels up - :D – Danushka Gunawardena Jan 06 '21 at 13:53
  • ok. I think, do you install `@angular-devkit/build-angular` as devDependencies? – Slava Jan 06 '21 at 14:01
  • yes i did - but it keeps creating the node_modules under the project folder - which is not what i desire. – Danushka Gunawardena Jan 06 '21 at 14:10
  • You can customize the location for install node_modules. Look here: [link](https://stackoverflow.com/questions/14742553/how-to-set-custom-location-for-local-installation-of-npm-package) – Slava Jan 06 '21 at 15:27