nitte93user3232918 nitte93user3232918 - 5 months ago 122
Node.js Question

Heroku error: Cannot find module webpack

heroku local web
works fine but
heroku open
is throwing Application error.

I checked the log file.
It says : Cannot find module webpack.
Complete log file.

Niteshs-MacBook-Pro:nyps nitesh$ heroku logs --tail
2016-06-16T03:40:53.132495+00:00 heroku[api]: Enable Logplex by nitesh@campusdiaries.com
2016-06-16T03:40:53.132551+00:00 heroku[api]: Release v2 created by nitesh@campusdiaries.com
2016-06-16T03:45:07.332337+00:00 heroku[api]: Deploy 690eea8 by nitesh@campusdiaries.com
2016-06-16T03:45:07.332405+00:00 heroku[api]: Release v3 created by nitesh@campusdiaries.com
2016-06-16T03:45:07.331714+00:00 heroku[api]: Scale to web=1 by nitesh@campusdiaries.com
2016-06-16T03:45:07.704674+00:00 heroku[slug-compiler]: Slug compilation finished
2016-06-16T03:45:07.704663+00:00 heroku[slug-compiler]: Slug compilation started
2016-06-16T03:45:14.763803+00:00 heroku[web.1]: Starting process with command `node server.js`
2016-06-16T03:45:17.000120+00:00 app[web.1]: module.js:341
2016-06-16T03:45:17.000129+00:00 app[web.1]: throw err;
2016-06-16T03:45:17.000135+00:00 app[web.1]:
2016-06-16T03:45:17.000135+00:00 app[web.1]: ^
2016-06-16T03:45:17.000140+00:00 app[web.1]: Error: Cannot find module 'webpack'
2016-06-16T03:45:17.000141+00:00 app[web.1]: at Function.Module._resolveFilename (module.js:339:15)
2016-06-16T03:45:17.000141+00:00 app[web.1]: at Function.Module._load (module.js:290:25)
2016-06-16T03:45:17.000142+00:00 app[web.1]: at Module.require (module.js:367:17)
2016-06-16T03:45:17.000142+00:00 app[web.1]: at require (internal/module.js:20:19)
2016-06-16T03:45:17.000143+00:00 app[web.1]: at Object.<anonymous> (/app/server.js:1:77)
2016-06-16T03:45:17.000144+00:00 app[web.1]: at Object.Module._extensions..js (module.js:422:10)
2016-06-16T03:45:17.000144+00:00 app[web.1]: at Module._compile (module.js:413:34)
2016-06-16T03:45:17.000145+00:00 app[web.1]: at Function.Module._load (module.js:314:12)
2016-06-16T03:45:17.000146+00:00 app[web.1]: at Function.Module.runMain (module.js:447:10)
2016-06-16T03:45:17.000145+00:00 app[web.1]: at Module.load (module.js:357:32)
2016-06-16T03:45:18.010833+00:00 heroku[web.1]: Process exited with status 1
2016-06-16T03:45:18.019746+00:00 heroku[web.1]: State changed from starting to crashed
2016-06-16T03:45:18.020059+00:00 heroku[web.1]: State changed from crashed to starting
2016-06-16T03:45:20.364946+00:00 heroku[web.1]: Starting process with command `node server.js`
2016-06-16T03:45:22.317904+00:00 app[web.1]: Error: Cannot find module 'webpack'
2016-06-16T03:45:22.317905+00:00 app[web.1]: at Function.Module._resolveFilename (module.js:339:15)
2016-06-16T03:45:22.317899+00:00 app[web.1]:
2016-06-16T03:45:22.317877+00:00 app[web.1]: module.js:341
2016-06-16T03:45:22.317905+00:00 app[web.1]: at Function.Module._load (module.js:290:25)
2016-06-16T03:45:22.317892+00:00 app[web.1]: throw err;
2016-06-16T03:45:22.317909+00:00 app[web.1]: at Module.load (module.js:357:32)
2016-06-16T03:45:22.317906+00:00 app[web.1]: at Module.require (module.js:367:17)
2016-06-16T03:45:22.317910+00:00 app[web.1]: at Function.Module._load (module.js:314:12)
2016-06-16T03:45:22.317907+00:00 app[web.1]: at require (internal/module.js:20:19)
2016-06-16T03:45:22.317908+00:00 app[web.1]: at Module._compile (module.js:413:34)
2016-06-16T03:45:22.317907+00:00 app[web.1]: at Object.<anonymous> (/app/server.js:1:77)
2016-06-16T03:45:22.317908+00:00 app[web.1]: at Object.Module._extensions..js (module.js:422:10)
2016-06-16T03:45:22.317898+00:00 app[web.1]: ^
2016-06-16T03:45:22.317910+00:00 app[web.1]: at Function.Module.runMain (module.js:447:10)
2016-06-16T03:45:23.310093+00:00 heroku[web.1]: Process exited with status 1
2016-06-16T03:45:23.327129+00:00 heroku[web.1]: State changed from starting to crashed
2016-06-16T03:45:30.105406+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=nyps.herokuapp.com request_id=096eccfb-7363-4137-88ef-c15389e7a664 fwd="106.51.20.194" dyno= connect= service= status=503 bytes=
2016-06-16T03:45:32.009229+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=nyps.herokuapp.com request_id=50951c24-4f9a-4347-963c-70c48560ab90 fwd="106.51.20.194" dyno= connect= service= status=503 bytes=
2016-06-16T03:55:36.073640+00:00 heroku[slug-compiler]: Slug compilation finished
2016-06-16T03:55:36.073633+00:00 heroku[slug-compiler]: Slug compilation started
2016-06-16T03:55:35.881416+00:00 heroku[api]: Deploy 85518b7 by nitesh@campusdiaries.com
2016-06-16T03:55:35.881515+00:00 heroku[api]: Release v4 created by nitesh@campusdiaries.com
2016-06-16T03:55:36.170187+00:00 heroku[web.1]: State changed from crashed to starting
2016-06-16T03:55:51.915142+00:00 heroku[web.1]: Starting process with command `node server.js`
2016-06-16T03:55:57.123301+00:00 app[web.1]: ==>

Answer

This is more of a trouble shoot answer, but this issue generally arises with one of two issues:

  1. webpack is globally installed (at some point you did npm install webpack -g)
  2. webpack is installed as a devDependency.

If you are running a server that require's in webpack, you're going to install it as a dependency.

If you're not doing any serverside middleware, then setting webpack as a devDependency is generally what you want.