tinytanks tinytanks - 26 days ago 13
Node.js Question

npm missing package after npm install

I decided to deploy my software in a remote machine, but when I started "npm install" to add every package of the package.json it is impossible to add "supertest" package. I tried in many way to solve the problem, deleting node_modules and restart npm install twice or use Yarn instead of 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.


this is my 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"
}
}

Answer Source

Supertest is in devDependencies and if you run npm install with flag --production or NODE_ENV is equal to production it will not be installed. You can move it to dependencies or change your NODE_ENV. You can find more info about it in documentation