我对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
正如您在错误消息中看到的,我有节点v7.4.0和npm v4.1.2 ...以前我运行的是节点v6.9.2,但是我在收到此错误后仍然更新但仍然没有更改...另外我不知道它是否重要,但我正在运行Windows 10.我已经尝试过npm cache clear
解决方案,但这对我不起作用。
答案 0 :(得分:8)
这是正常的,当你运行npm run test
时,它会在package.json
执行相应的脚本,所以这一行
"test": "echo \"Error: no test specified\" && exit 1"
正如您所看到的,它会引发错误并退出,状态代码不是0(exit 1
),这是一个错误代码。
您必须通过其他真正运行测试的内容来更改测试脚本。