When I deploy my node.js server to Heroku it throws the following error:
2018-12-27T10:10:28.370131+00:00 app[web.1]: Error: Cannot find module './lib/utils' 2018-12-27T10:10:28.370137+00:00 app[web.1]: at Function.Module._resolveFilename (module.js:538:15) 2018-12-27T10:10:28.370139+00:00 app[web.1]: at Function.Module._load (module.js:468:25) 2018-12-27T10:10:28.370141+00:00 app[web.1]: at Module.require (module.js:587:17) 2018-12-27T10:10:28.370142+00:00 app[web.1]: at require (internal/module.js:11:18) 2018-12-27T10:10:28.370145+00:00 app[web.1]: at Object. (/app/node_modules/mongodb-core/index.js:5:15) 2018-12-27T10:10:28.370146+00:00 app[web.1]: at Module._compile (module.js:643:30) 2018-12-27T10:10:28.370148+00:00 app[web.1]: at Object.Module._extensions..js (module.js:654:10) 2018-12-27T10:10:28.370149+00:00 app[web.1]: at Module.load (module.js:556:32) 2018-12-27T10:10:28.370151+00:00 app[web.1]: at tryModuleLoad (module.js:499:12) 2018-12-27T10:10:28.370153+00:00 app[web.1]: at Function.Module._load (module.js:491:3)
My node.js server is fully working locally, and saving to the database without any problem. Running npm install
locally with my current package.json does create a utils.js file under /lib in the node modules. heroku local web
build just fine.
I have been re-initiating my package.json time and time again with no success.
Current package.json is as follows:
{
"name": "temperature_web_app",
"version": "1.0.0",
"main": "server.js",
"scripts": {
"start": "node server.js"
},
"author": "Simon Rosengren",
"license": "ISC",
"dependencies": {
"body-parser": "^1.18.3",
"express": "^4.16.4",
"mongodb": "^3.1.10",
"mqtt": "^2.18.8"
},
"engines": {
"node": "8.9.4"
}
}
Not ignoring the node_modules folder when pushing to heroku master seem to have been the problem.
Removing the node_modules folder and then pushing to master did the trick.
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.