Child module is unable to install dependencies (global install) - Relative path issue?

Viewed 229

I have an npm package with a structure like this:

./
  ./backend
    ./package.json
  package.json

So basically two npm modules in the same folder, one being a child of the other, file structure wise.

The way I install is, is that I put a post-install script in the parent package.json:

"postinstall": "cd backend && npm install && cd .."

What happens ONLY if I install it globally: It first prints some warnings that basically the packages weren't installed. Like this:

npm WARN enoent ENOENT: no such file or directory, open '/usr/lib/node_modules/inschpektor/backend/node_modules/trim-newlines/package.json'

Those appear for all dependencies in ./backend/package.json.

I already run the installation with the --unsafe-perm flag:

npm install -g inschpektor --unsafe-perm which installs the parent package.json, that contains the postinstall script.

The final log error message I get is this one:

npm ERR! path /usr/lib/node_modules/inschpektor/backend/node_modules/ansi-regex/package.json
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall open
npm ERR! enoent ENOENT: no such file or directory, open '/usr/lib/node_modules/inschpektor/backend/node_modules/ansi-regex/package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent 

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/codepleb/.npm/_logs/2019-01-02T01_52_46_911Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 254
npm ERR! inschpektor@0.9.1 postinstall: `cd backend && npm install && cd ..`
npm ERR! Exit status 254
npm ERR! 
npm ERR! Failed at the inschpektor@0.9.1 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/codepleb/.npm/_logs/2019-01-02T01_52_47_511Z-debug.log

What am I doing wrong? Or do you maybe see flaws in the way I'm setting things up?

Here is the link to get git repo, if you would like to further analyze it: https://github.com/codepleb/inschpektor

0 Answers
Related