子模块无法安装依赖项(全局安装) - 相对路径问题?

cod*_*leb 5 node.js npm node-modules npm-install npm-scripts

我有一个npm包,其结构如下:

./
  ./backend
    ./package.json
  package.json
Run Code Online (Sandbox Code Playgroud)

所以基本上两个npm模块在同一个文件夹中,一个是另一个的子文件,文件结构明智.

我安装的方式是,我将一个安装后的脚本放在父package.json中:

"postinstall": "cd backend && npm install && cd .."
Run Code Online (Sandbox Code Playgroud)

如果我全局安装它会发生什么:它首先打印一些警告,基本上没有安装包.像这样:

npm WARN enoent ENOENT: no such file or directory, open '/usr/lib/node_modules/inschpektor/backend/node_modules/trim-newlines/package.json'
Run Code Online (Sandbox Code Playgroud)

那些出现在所有依赖关系中./backend/package.json.

我已经使用--unsafe-perm标志运行安装:

npm install -g inschpektor --unsafe-perm 它安装包含postinstall脚本的父package.json.

我得到的最终日志错误消息是这一个:

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
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?或者你可能会看到我正在设置的方式存在缺陷?

以下是获取git repo的链接,如果您想进一步分析它:https://github.com/codepleb/inschpektor