npm 安装后 npm 缺少包

npm missing package after npm install

我决定在远程机器上部署我的软件,但是当我开始 "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"
  }
}

SupertestdevDependencies 中,如果你 运行 npm install 带有标志 --productionNODE_ENV 等于 production 它不会被安装。您可以将其移动到 dependencies 或更改您的 NODE_ENV。您可以在 documentation

中找到更多相关信息