I'm pretty sure this is a problem with my environment and no shortcoming of the supertest module. A unit test a colleague wrote requires supertest. It runs just fine on everyone's machine except mine. The stacktrace is this:
pmacklin@PMACKLIN-7L /c/Code/bakery-backend (master)
$ mocha tests/routes/modules/mcSpec.js
module.js:340
throw err;
^
Error: Cannot find module 'methods'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (c:\Code\backend\node_modules\supertest\index.js:6:15)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (c:\Code\backend\tests\routes\modules\mcSpec.js:5:13)
Line 5 of mcSpec.js is just request = require('supertest'), and line six of your (very fine) index.js is var methods = require('methods'). I've tried an npm update on the backend project, an npm install -g supertest and npm install -g methods, which all seemed to complete without error.
I am on win7 and using gitbash for running all my node related things. Have you by any chance worked with supertest on this platform setup? What is this enigmatic methods module and how can I get require to find it?
I have this problem too, but I'm running in a linux Docker container (inside Windows), so I don't think it is because you are on Windows
The issue for me is caused by node_modules/supertest not having its own node_modules directory. I ran npm uninstall supertest followed by npm install supertest and the problem resolved itself.
Most helpful comment
The issue for me is caused by
node_modules/supertestnot having its own node_modules directory. I rannpm uninstall supertestfollowed bynpm install supertestand the problem resolved itself.