NodeJS NPM未运行postinstall

wnvonmuf  于 2023-04-20  发布在  Node.js
关注(0)|答案(1)|浏览(365)

我已经安装了一个名为@company/cdk-library的自定义软件包。
它有package.json脚本:

"scripts": {
    "test": "jest",
    "build": "tsc",
    "prepublishOnly": "npx tsc --skipLibCheck",
    "installLambdas": "(cd constructs/account/mylambda/code/ && npm i)",
    "postinstall": "npm run installLambdas"
  },

当我使用以下命令将此包安装到我的项目中时:npm i @mycompany/cdk-library@5.0.0 --foreground-script
我没有得到任何运行postinstall脚本的指示。如果我检查目录,那里也没有依赖项。
install的输出:

➜  cdk git:(cdk-update) ✗ npm i @mycompany/cdk-library@5.0.0 --foreground-scripts
npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
npm WARN deprecated source-map-url@0.4.1: See https://github.com/lydell/source-map-url#deprecated
npm WARN deprecated source-map-resolve@0.5.3: See https://github.com/lydell/source-map-resolve#deprecated
npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
npm WARN deprecated sane@4.1.0: some dependency vulnerabilities fixed, support for node < 10 dropped, and newer ECMAScript syntax/features added

added 504 packages, and audited 523 packages in 16s

25 packages are looking for funding
  run `npm fund` for details

1 critical severity vulnerability

To address all issues, run:
  npm audit fix

Run `npm audit` for details.

但是,如果我通过运行cd node_modules/@mycompany/cdk-library && npm run postinstall手动执行此操作
它运行得很好,输出:

cdk-library git:(cdk-update) ✗ npm run postinstall                                                               

> @mycompany/cdk-library@5.0.0 postinstall
> npm run installLambdas

npm WARN deprecated axios@0.19.2: Critical security vulnerability fixed in v0.21.1. For more information, see https://github.com/axios/axios/pull/3410

added 82 packages, and audited 83 packages in 1s

...

有谁知道为什么我安装软件包时安装后没有运行?

rqqzpn5f

rqqzpn5f1#

我知道这已经有一段时间了,但我自己也遇到了它,我最终解决的是,“postinstall”只会在您实际使用“npm install ...”时调用。
如果你碰巧使用了快捷方式“npm i ...”,它不会被调用。你需要为“posti”添加一个脚本条目,以便它也能使用快捷方式。
希望这对其他人有帮助。

相关问题