Ron Ron - 8 months ago 179
AngularJS Question

How to move node_modules to a different location correctly

I am trying to move my node_modules to a different location, what I did is deleted the node_modules and moved the package.json to the location I wanted it to be installed, then I ran

npm install
which installed the node_modules where I wanted but now, if I run
npm start
, the server starts and I get alot of errors:

(index):5 GET http://localhost:3000/node_modules/bootstrap/dist/css/bootstrap.min.css
(index):9 GET http://localhost:3000/node_modules/es6-shim/es6-shim.min.js
(index):10 GET http://localhost:3000/node_modules/systemjs/dist/system-polyfills.js
(index):12 GET http://localhost:3000/node_modules/angular2/bundles/angular2-polyfills.js
(index):13 GET http://localhost:3000/node_modules/systemjs/dist/system.src.js
(index):14 GET http://localhost:3000/node_modules/rxjs/bundles/Rx.js
(index):15 GET http://localhost:3000/node_modules/angular2/bundles/
(index):16 GET http://localhost:3000/node_modules/angular2/bundles/
(index):21 Uncaught ReferenceError: System is not defined(anonymous function) @ (index):21

I updated the index.html file to use the files from root node_modules instead of current dir's node_modules.

What else am I supposed to do to make it work?

Notice that the index.html is in a differnt dir then the node_modules

Ron Ron

The solution is as follow:

  1. Create bs-config.json file at the same dir where you have package.json file
  2. Put the following json in that bs-config.json file:

    { "server": { "baseDir": "path/to/your/base/dir/where/you/have/the/index.html/of/your/app", "routes": { "/node_modules": "/path/to/node/modules/relatively/to/this/file" } } }

  3. Edit your package.json file "lite": "lite-server --c bs-config.json"

  4. Run npm start and it will work like a magic :D