3

I have a following project structure:

project structure

install.js:

var path = require('path'),
    exec = require('child_process').exec;

exec('npm install', {cwd: path.join(__dirname, './some_modules')});

package.json:

"scripts": {
  "install": "node install.js"
},
"dependencies": {
  "gulp": "3.8.10"
},

And have some dependencies in some_modules/package.json.

In case installation locally we get the expected result:

enter image description here

But in case installation globally (with -g parameter) we have following broken structure: enter image description here

Question: How to get rid of the influence -g parameter for install.js -> exec('npm install') ?

Try it here: https://github.com/MishaMykhalyuk/npm-i-with-g-and-hooks (npm install -g git+https://github.com/MishaMykhalyuk/npm-i-with-g-and-hooks.git).

  • I wonder if running "npm dedupe" would have a positive effect on all this. If it were me I'd make a good backup of the folder structure, run "npm dedupe" and compare the results. If it didn't help, then put things back from your backup. https://docs.npmjs.com/cli/dedupe – Michael Blankenship Jun 21 '15 at 21:50
  • It's seems a bit hackish :) Besides, I need a stable solution for production ("This feature is experimental, and may change in future versions.") – Mykhailo Mykhaliuk Jun 21 '15 at 22:04
  • It works if you specify packages by name `exec('npm install glup -g',…`. In which case you can [parse the package.json](http://stackoverflow.com/questions/9153571/is-there-a-way-to-get-version-from-package-json-in-nodejs-code) and dynamically create your command including those packages – laggingreflex Jun 21 '15 at 22:59

0 Answers0