Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix 'Error: Cannot find module 'supertest''

I am new to nodejs. I got one nodejs application and i was just trying to run the tests this app contains. So i tried to run npm test command after installing all packages using npm install. But npm test is throwing below error always

internal/modules/cjs/loader.js:657
    throw err;
    ^

Error: Cannot find module 'supertest'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:655:15)
    at Function.Module._load (internal/modules/cjs/loader.js:580:25)
    at Module.require (internal/modules/cjs/loader.js:711:19)
    at require (internal/modules/cjs/helpers.js:14:16)

I tried to uninstall and install supertest but it did not help. I see there is no node_modules folder inside supertest. Would that be an issue? How do we fix it?

Here is the file which is using supertest

var fs = require('fs')
var request = require('supertest')

var config = require('./config').getConfig()
var url = config.url

var caCert
if (config.caCertFile) {
  caCert = fs.readFileSync(config.caCertFile)
}

var preparedRequest = function () {
  return caCert ? request.agent(url, { ca: caCert }) : request(url)
}

module.exports = preparedRequest
like image 549
catch_aag Avatar asked Sep 20 '25 11:09

catch_aag


1 Answers

It seems that supertest is not in your package.json depencendies. So If you run npm install, it will not install supertest.

Just run npm install supertest to install supertest, or npm install --save supertest to install it and add the dependency in your package.json so the next time you run npm install it will install supertest too :)

like image 125
Antoine Prudhomme Avatar answered Sep 22 '25 03:09

Antoine Prudhomme