mongoose works fine on the 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)
OK! I took me a while but I found the solution
Good luck :)
I recently ran into a similar issue. I am using the MEAN stack with mongoose as my ODM and hosting on Heroku:
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 stated here (under section Cache Behavior), I had to remove my node_modules
directory from the git repo (also recommended in the Heroku docs). See this thread on how to remove a directory from git.
Also, adding "node_modules" directory to your .gitignore file is a good idea. NOTE: This does not remove the files from git, you still have to remove any previously committed files or directories that you want ignored.
I simply ran heroku run bash
in the cloned directory and typed in rm -rf node_modules
and ran npm install
from there. Simply ran the server through heroku run bash
and worked fine! Hopefully this will work for you. Ensure to have node_modules
in your .gitignore
file.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.