【问题标题】:npm not running scripts in package.jsonnpm 未在 package.json 中运行脚本
【发布时间】:2020-03-04 16:37:47
【问题描述】:

问题是,当我执行 npm startnpm run customScriptCommand 时,npm 只是没有对项目做任何事情,而是快速在终端中返回新行。

我尝试从我的机​​器中删除 node 和 npm,然后为 node 和 npm 进行 brew 安装,但它并没有解决问题。

然后我尝试从 brew 安装中删除 node 和 npm 并从 nvm 再次安装它,但它也没有解决问题。

NPM 详情

npm -v -> 6.11.3
which npm -> /usr/local/bin/npm

NodeJS 详情

node -v -> v12.12.0
which node ->/usr/local/bin/node

package.json 中的脚本

"scripts": {
    "start": "node ./bin/www",
    "devstart": "DEBUG=app-name:* nodemon ./bin/www", //I've changed my actual app name to "app-name"
  },

如果我这样做 node ./bin/wwwDEBUG=app-name:* nodemon ./bin/www 它将起作用:

更新

  • 我在同事的机器上尝试过其他没有问题的项目,git clonenpm install 并尝试运行该项目,但仍然失败

  • 即使是我刚刚完成的新项目npm init -y 也失败了,

{
   "name": "test"
   "version": "1.0.0",
   "description": "",
   "main": "index.js",
   "scripts": {
       "test": "echo \"Error: no test specified\" && exit 1"
   },
   "keywords": [],
   "author": "itsme",
   "license": "ISC"
}

【问题讨论】:

  • 你能发布你的整个 package.json 吗?您显示的位看起来正确。
  • 即使有了我刚刚做的新项目npm init,它仍然失败了。 ``` mkdir test cd test && npm init -y ``` 结果 package.json: `` { "name": "test", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "keywords": [], "author": "nrajan" ,“许可证”:“ISC”}```

标签: javascript node.js npm npm-scripts


【解决方案1】:

npm config set ignore-scripts false 会为您解决问题。

我的朋友,斗争是真实的,从现在开始不再遵循随机教程。

https://github.com/npm/cli/issues/541

【讨论】:

  • 谢谢,有趣的是我确实重新安装了几次node安装没有遇到这个变量设置。希望其他人能得到帮助
【解决方案2】:

你可以安装 yarn 并且它可以工作;只需运行yarn start。至于是什么导致的问题我不知道。

【讨论】:

  • 这应该是评论而不是答案。
猜你喜欢
  • 2022-11-20
  • 2014-06-26
  • 2015-05-07
  • 2015-07-08
  • 2018-12-03
  • 1970-01-01
  • 2018-09-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多