运行npm命令时总是出现错误,尝试运行脚本时也是如此。

5

我有一个NPM的问题。最近,每当我尝试使用npm运行脚本时,它会给我一堵整墙的错误信息,即使我知道这些脚本是正确的,我也无法弄清原因...

package.json

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

您可以看到,这只是在运行npm init并按下几次回车后生成的...但是当我运行npm run test时,我会得到以下结果...

> testing@1.0.0 test C:\Users\user\Desktop\testing
> echo "Error: no test specified" && exit 1

"Error: no test specified"

npm ERR! Windows_NT 10.0.14393
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "test"
npm ERR! node v7.4.0
npm ERR! npm  v4.1.2
npm ERR! code ELIFECYCLE
npm ERR! testing@1.0.0 test: `echo "Error: no test specified" && exit 1`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the testing@1.0.0 test script 'echo "Error: no test specified" && exit 1'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the testing package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     echo "Error: no test specified" && exit 1
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs testing
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls testing
npm ERR! There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?

npm ERR! Please include the following file with any support request:
npm ERR!     C:\Users\user\Desktop\testing\npm-debug.log

正如您在错误信息中看到的那样,我使用的是node v7.4.0和npm v4.1.2... 之前我使用的是node v6.9.2,但在遇到此错误后我已经更新了版本,但仍然没有改变... 另外我不知道这是否有很大影响,但我正在运行windows 10。我已经尝试过npm cache clear解决方案,但对我没有用。

1个回答

12

当您运行npm run test时,这是正常的,它将执行package.json中对应的脚本,因此这一行。

"test": "echo \"Error: no test specified\" && exit 1"

正如您所看到的,它会引发错误并退出,状态代码不为0(exit 1),这是一个错误代码。

您必须通过其他真正运行测试的方式来更改测试脚本。


我明白了,谢谢你的帮助。现在它可以工作了,但是之前当我尝试通过npm脚本运行webpack-dev-server时,它会抛出错误...这可能是因为我没有最新版本的node和npm吗? - Reel
1
它可能是一个配置问题,也可能是。为了轻松管理节点版本,我建议您使用nvm。如果您仍然有问题,请打开一个新的问题,并提供有关您配置的更多详细信息。 - ThomasThiebaud

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接