Error: cannot find module "./drivers" with mongoose only on server

mongoose works great on computer

but on the server, I get this error:

Error: Cannot find module './drivers' at Function.Module._resolveFilename (module.js:336:15) at Function.Module._load (module.js:278:25) at Function.<anonymous> (/usr/local/lib/node_modules/pm2/node_modules/pmx/lib/transaction.js:59:21) at Module.require (module.js:365:17) at require (module.js:384:17) at Object.<anonymous> (/var/www/html/WTV.com/node_modules/mongoose/lib/schema.js:5:16) at Module._compile (module.js:460:26) at Object.Module._extensions..js (module.js:478:10) at Module.load (module.js:355:32) at Function.Module._load (module.js:310:12) 
+4
source share
3 answers

OK! I took the time but found a solution

  • at the command line write: heroku configuration: set NODE_MODULES_CACHE = false --app
  • make some changes and click project
  • at the command line write: heroku config: set NODE_MODULES_CACHE = true --app

Good luck :)

+4
source

I just ran heroku run bash in the cloned directory and typed rm -rf node_modules and ran npm install from there. Just started the server through heroku run bash and worked fine! Hope this works for you. Make sure node_modules has node_modules in your .gitignore file.

+1
source

I recently encountered a similar problem. I use the MEAN stack with mongoose as my ODM and Heroku hosting:

 Error: Cannot find module './drivers' at Function.Module._resolveFilename (module.js:326:15) at Function.Module._load (module.js:277:25) at Module.require (module.js:354:17) at require (internal/module.js:12:17) at Object.<anonymous> (/app/node_modules/mongoose/lib/schema.js:5:16) at Module._compile (module.js:410:26) at Object.Module._extensions..js (module.js:417:10) at Module.load (module.js:344:32) at Module.require (module.js:354:17) at Function.Module._load (module.js:301:12) at require (internal/module.js:12:17) Process exited with status 1 State changed from starting to crashed 

In addition to setting NODE_MODULES_CACHE=false , as indicated here (under the "Cache Behavior" section), I had to remove my node_modules directory from the git repository (also recommended in Heroku docs). See this thread on how to remove a directory from git.

Also, adding a node_modules directory to your .gitignore file is a good idea. NOTE. This does not delete files from git, you still have to delete any previously committed files or directories that you want to ignore.

0
source

All Articles