我正在尝试将我的node.js应用程序部署到heroku。
我在git push heroku master
上收到此错误:
> on-headers@1.0.1 test /tmp/build_4d6fe429e576b4e42425b713c87264e9/node_modules/response-time/node_modules/on-headers
> mocha --reporter spec --bail --check-leaks test/
/tmp/build_4d6fe429e576b4e42425b713c87264e9/node_modules/mocha/lib/utils.js:626
throw new Error("cannot resolve path (or pattern) '" + path + "'");
^
Error: cannot resolve path (or pattern) 'test/'
at Object.lookupFiles (/tmp/build_4d6fe429e576b4e42425b713c87264e9/node_modules/mocha/lib/utils.js:626:15)
at /tmp/build_4d6fe429e576b4e42425b713c87264e9/node_modules/mocha/bin/_mocha:316:30
at Array.forEach (native)
at Object.<anonymous> (/tmp/build_4d6fe429e576b4e42425b713c87264e9/node_modules/mocha/bin/_mocha:315:6)
at Module._compile (module.js:435:26)
at Object.Module._extensions..js (module.js:442:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:311:12)
at Function.Module.runMain (module.js:467:10)
at startup (node.js:136:18)
at node.js:963:3
> node-statsd@0.1.1 test /tmp/build_4d6fe429e576b4e42425b713c87264e9/node_modules/soluto-monitor/node_modules/node-statsd
> mocha -R spec
/tmp/build_4d6fe429e576b4e42425b713c87264e9/node_modules/mocha/lib/utils.js:626
throw new Error("cannot resolve path (or pattern) '" + path + "'");
^
Error: cannot resolve path (or pattern) 'test'
at Object.lookupFiles (/tmp/build_4d6fe429e576b4e42425b713c87264e9/node_modules/mocha/lib/utils.js:626:15)
at /tmp/build_4d6fe429e576b4e42425b713c87264e9/node_modules/mocha/bin/_mocha:316:30
at Array.forEach (native)
at Object.<anonymous> (/tmp/build_4d6fe429e576b4e42425b713c87264e9/node_modules/mocha/bin/_mocha:315:6)
at Module._compile (module.js:435:26)
at Object.Module._extensions..js (module.js:442:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:311:12)
at Function.Module.runMain (module.js:467:10)
at startup (node.js:136:18)
at node.js:963:3
...
..并且每个node_modules子目录都有错误Error: cannot resolve path (or pattern) 'test/'
。
我的package.json看起来或多或少是这样的:
{
"name": "my-module",
"version": "0.1.0",
"description": "My Module",
"dependencies": {
"azure-storage": "0.6.0",
"bluebird": "3.0.6",
"body-parser": "1.14.1",
"cors": "2.7.1",
"dotenv": "^1.2.0",
"express": "3.3.3",
"moment": "2.10.6",
"request-promise": "1.0.2",
"rx": "4.0.7",
"shisell": "0.0.2",
"striptags": "2.0.4",
"winston": "2.1.1"
},
"devDependencies": {
"chai": "^3.4.1",
"chai-as-promised": "^5.1.0",
"mocha": "^2.3.4",
"mock-require": "^1.2.1",
"sinon": "^1.17.2",
"sinon-chai": "^2.8.0",
"supertest": "^1.1.0"
},
"main": "server.js",
"engines": {
"node": "4.2.3"
},
"scripts": {
"test": "mocha"
}
}
似乎mocha试图在每个依赖项内的node_modules内运行。我设法通过在其中一个node_modules目录中运行mocha
来本地重现错误。
我尝试从package.json中删除test
脚本,但仍然遇到同样的错误。
我是heroku部署的新手。据我所知,一旦我git推送到heroku然后heroku运行npm install,如果有一个测试脚本它将运行。但是我不明白是什么导致它尝试在node_modules的子目录中运行mocha(为什么即使我没有在package.json中指定测试脚本也会发生这种情况)。
有什么想法吗?
P.S。当我在我的机器上本地运行时,这不会发生。
答案 0 :(得分:0)
原来我在heroku上设置了这个环境变量:NPM_CONFIG_NPAT=true
,它导致npm在所有安装上运行测试,如下所述:
https://docs.npmjs.com/misc/config#npat