> xx@1.0.0 test /Users/beidan/Desktop/xxx > echo "Error: no test specified" && exit 1
Error: no test specified npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! xx@1.0.0 test: `echo "Error: no test specified" && exit 1` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the xx@1.0.0 test script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm WARN Local package.json exists, but node_modules missing, did you mean to install?
npm ERR! A complete log ofthis run can be found in: npm ERR! /Users/beidan/.npm/_logs/2021-02-19T06_40_42_472Z-debug.log
如果直接在终端中执行 npm test, 也是可以得到一样的结果
➜ xxx npm test
> xx@1.0.0 test /Users/beidan/Desktop/xxx > echo "Error: no test specified" && exit 1
Error: no test specified npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! xx@1.0.0 test: `echo "Error: no test specified" && exit 1` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the xx@1.0.0 test script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm WARN Local package.json exists, but node_modules missing, did you mean to install?
npm ERR! A complete log ofthis run can be found in: npm ERR! /Users/beidan/.npm/_logs/2021-02-19T06_40_42_472Z-debug.log
{ "scripts": { "lint": "eslint .", "test": "echo \"Error: no test specified\" && exit 1", "ci": "npm run lint && npm test"// 此时 npm run ci 即会依次执行 npm run lint , npm run test } }
> xx@1.0.0 test /Users/beidan/Desktop/xxx > echo "Error: no test specified" && exit 1
Error: no test specified npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! xx@1.0.0 test: `echo "Error: no test specified" && exit 1` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the xx@1.0.0 test script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm WARN Local package.json exists, but node_modules missing, did you mean to install?
npm ERR! A complete log ofthis run can be found in: npm ERR! /Users/beidan/.npm/_logs/2021-02-19T06_48_18_141Z-debug.log
静默消息
如果想减少错误日志并非防止脚本抛出错误, 可以使用下面的命令来“静默”处理, (比如在 ci 中,即使测试命令失败,也希望整个管道继续运行,就可以使用这个命令)
npm run <script> --silent // 或者 npm run <script> -s
如果脚本名不存在时不想报错,可以使用 --if-present ,比如:npm run <script> --if-present