我决定在远程计算机上部署我的软件,但是当我开始“npm install”添加package.json的每个包时,就不可能添加“supertest”包。我尝试了很多方法来解决问题,删除node_modules并重启npm install两次或使用Yarn而不是NPM。
$ npm install supertest
+ supertest@2.0.1
removed 13 packages and updated 3 packages in 2.28s
api-http@remotemachine:~/api-http$ npm test
> api-http@0.0.1 test /home/api-http/api-http
> NODE_ENV=test mocha --recursive test
module.js:487
throw err;
^
Error: Cannot find module 'supertest'
at Function.Module._resolveFilename (module.js:485:15)
at Function.Module._load (module.js:437:25)
at Module.require (module.js:513:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/home/api-http/api-http/test/app/controllers/crop.js:3:17)
at Module._compile (module.js:569:30)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:503:32)
at tryModuleLoad (module.js:466:12)
at Function.Module._load (module.js:458:3)
at Module.require (module.js:513:17)
at require (internal/module.js:11:18)
at /home/api-http/api-http/node_modules/mocha/lib/mocha.js:230:27
at Array.forEach (native)
at Mocha.loadFiles (/home/api-http/api-http/node_modules/mocha/lib/mocha.js:227:14)
at Mocha.run (/home/api-http/api-http/node_modules/mocha/lib/mocha.js:513:10)
at Object.<anonymous> (/home/api-http/api-http/node_modules/mocha/bin/_mocha:480:18)
at Module._compile (module.js:569:30)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:503:32)
at tryModuleLoad (module.js:466:12)
at Function.Module._load (module.js:458:3)
at Function.Module.runMain (module.js:605:10)
at startup (bootstrap_node.js:158:16)
at bootstrap_node.js:575:3
npm ERR! Test failed. See above for more details.
这是我的package.json:
{
"name": "api-http",
"version": "0.0.1",
"private": true,
"main": "app.js",
"scripts": {
"start": "node app.js",
"test": "NODE_ENV=test mocha --recursive test",
"test:coverage": "nyc npm test",
"test:unit": "mocha --recursive test/middleware test/models test/routes",
"test:integration": "mocha --recursive test/integration"
},
"dependencies": {
"async": "^2.5.0",
"body-parser": "^1.13.3",
"chai-http": "^3.0.0",
"compression": "^1.7.0",
"cookie-parser": "^1.3.3",
"cors": "^2.8.4",
"d3": "^4.10.0",
"express": "^4.13.3",
"glob": "^6.0.4",
"http-status": "^1.0.1",
"jade": "^1.11.0",
"lodash": "^4.17.4",
"method-override": "^2.3.0",
"mocha": "^3.5.0",
"morgan": "^1.6.1",
"mysql": "^2.14.1",
"only": "0.0.2",
"request": "^2.81.0",
"sequelize": "^3.5.1",
"serve-favicon": "^2.3.0",
"shuffle-array": "^1.0.1",
"terraformer": "^1.0.8"
},
"devDependencies": {
"chai": "^3.5.0",
"debug": "^2.6.8",
"grunt": "^1.0.1",
"grunt-contrib-watch": "^1.0.0",
"grunt-develop": "^0.4.0",
"load-grunt-tasks": "^3.2.0",
"nyc": "^10.0.0",
"supertest": "^2.0.1",
"time-grunt": "^1.2.1"
}
}
答案 0 :(得分:1)
Supertest
位于devDependencies
,如果您使用标记为npm install
的{{1}}或--production
等于NODE_ENV
,则不会安装production
。您可以将其移至dependencies
或更改NODE_ENV
。您可以在documentation