简体   繁体   English

npm package.json 中没有运行脚本

[英]npm not running scripts in package.json

The problem is that when I do npm start OR npm run customScriptCommand npm just not doing anything with the project and quickly just return new line in the terminal.问题是,当我执行npm startnpm run customScriptCommand npm 时,我只是不对项目做任何事情,并迅速在终端中返回新行。

I've tried removing node and npm from my machine and then do brew installation for node and npm, but it does not fix the problem.我试过从我的机器上删除节点和 npm,然后对节点和 npm 进行 brew 安装,但它没有解决问题。

Then I tried removing node and npm from the brew installation and installing it again from nvm, but it also does not fix the problem.然后我尝试从 brew 安装中删除节点和 npm 并从 nvm 再次安装它,但它也没有解决问题。

NPM Details NPM 详情

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

NodeJS Details节点详细信息

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

Scripts in package.json package.json 中的脚本

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

If I do node./bin/www OR DEBUG=app-name:* nodemon./bin/www it will work:如果我执行node./bin/wwwDEBUG=app-name:* nodemon./bin/www它将起作用:

在此处输入图像描述

Update更新

  • I've tried on other project that does not have problem on my colleague's machine, with git clone do npm install and tried to run the project, but it still failed我试过在我同事的机器上没有问题的其他项目,使用git clone do npm install并尝试运行该项目,但它仍然失败

  • Even with fresh project which I just did npm init -y it fail,即使是我刚做的新项目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"
}

npm config set ignore-scripts false would do the trick for you. npm config set ignore-scripts false会为您解决问题。

The struggle is real my friend, not following random tutorials from now.我的朋友,这场斗争是真实的,从现在开始不遵循随机教程。

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

Installing npm install --save-dev nodemon and running npm start did the magic for me安装npm install --save-dev nodemon并运行npm start对我来说很神奇

在此处输入图像描述

hard to tell without seeing the rest of your package.json but most likely when this happens it's because it is malformed somehow and NPM can't parse it. hard to tell without seeing the rest of your package.json but most likely when this happens it's because it is malformed somehow and NPM can't parse it.

You can install yarn and it works;您可以安装纱线并且它可以工作; just run yarn start .只需运行yarn start As to what caused the problem I have no idea.至于是什么导致了这个问题,我不知道。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM