Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Heroku error: Cannot find module webpack

Tags:

node.js

heroku

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 [email protected]
2016-06-16T03:40:53.132551+00:00 heroku[api]: Release v2 created by [email protected]
2016-06-16T03:45:07.332337+00:00 heroku[api]: Deploy 690eea8 by [email protected]
2016-06-16T03:45:07.332405+00:00 heroku[api]: Release v3 created by [email protected]
2016-06-16T03:45:07.331714+00:00 heroku[api]: Scale to web=1 by [email protected]
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 [email protected]
2016-06-16T03:55:35.881515+00:00 heroku[api]: Release v4 created by [email protected]
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]: ==> 🌎  Listening on port 3000. Open up http://localhost:3000/ in your browser.
2016-06-16T03:55:56.884371+00:00 app[web.1]: process  production
2016-06-16T03:56:46.013013+00:00 heroku[web.1]: Error R14 (Memory quota exceeded)
2016-06-16T03:56:46.012815+00:00 heroku[web.1]: Process running mem=556M(108.8%)
2016-06-16T03:56:51.994793+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2016-06-16T03:56:51.994793+00:00 heroku[web.1]: Stopping process with SIGKILL
2016-06-16T03:56:53.386252+00:00 heroku[web.1]: State changed from crashed to starting
2016-06-16T03:56:53.364620+00:00 heroku[web.1]: Process exited with status 137
2016-06-16T03:56:53.383770+00:00 heroku[web.1]: State changed from starting to crashed
2016-06-16T03:57:01.236167+00:00 heroku[router]: at=error code=H20 desc="App boot timeout" method=GET path="/" host=nyps.herokuapp.com request_id=3058277f-f351-4ff9-8cb7-e8500217bf1b fwd="106.51.20.194" dyno= connect= service= status=503 bytes=
2016-06-16T03:57:01.627497+00:00 heroku[web.1]: Starting process with command `node server.js`
2016-06-16T03:57:03.490555+00:00 app[web.1]: ==> 🌎  Listening on port 3000. Open up http://localhost:3000/ in your browser.
2016-06-16T03:57:03.405989+00:00 app[web.1]: process  production
2016-06-16T03:57:23.431249+00:00 app[web.1]: webpack built 114bd08e06394dc17ec8 in 19974ms
2016-06-16T03:58:01.964579+00:00 heroku[router]: at=error code=H20 desc="App boot timeout" method=GET path="/" host=nyps.herokuapp.com request_id=ba97ba30-cc4b-493f-8907-4341a650b361 fwd="106.51.20.194" dyno= connect= service= status=503 bytes=
2016-06-16T03:58:02.073841+00:00 heroku[web.1]: Stopping process with SIGKILL
2016-06-16T03:58:02.073797+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2016-06-16T03:58:02.741937+00:00 heroku[web.1]: Process exited with status 137
2016-06-16T03:58:02.770625+00:00 heroku[web.1]: State changed from starting to crashed
2016-06-16T03:58:04.232803+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=nyps.herokuapp.com request_id=db9f5b88-805d-4917-9eb4-2d4827572afc fwd="106.51.20.194" dyno= connect= service= status=503 bytes=
2016-06-16T03:58:06.684479+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=nyps.herokuapp.com request_id=6b3b9797-f3d9-48e5-aebd-c157a2603596 fwd="106.51.20.194" dyno= connect= service= status=503 bytes=
2016-06-16T03:58:42.837687+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=nyps.herokuapp.com request_id=6a3ca1a5-ed23-416a-b3cf-3e755ee9e88e fwd="106.51.20.194" dyno= connect= service= status=503 bytes=
2016-06-16T03:58:46.216435+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=nyps.herokuapp.com request_id=52e5d646-ef1d-418e-8196-ddc79d68001b fwd="106.51.20.194" dyno= connect= service= status=503 bytes=
2016-06-16T04:04:10.169663+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=nyps.herokuapp.com request_id=b27e2500-1b84-4d8c-90d1-412a95ca3b13 fwd="106.51.20.194" dyno= connect= service= status=503 bytes=
2016-06-16T04:04:11.771412+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=nyps.herokuapp.com request_id=e7e7c74e-656c-4b85-abde-48cc54e3367c fwd="106.51.20.194" dyno= connect= service= status=503 bytes=

I'm calling var webpack = require('webpack') in the first line of my server.js which is called using node server.js

I deleted node_module; rm -rf node_module Did npm install. Still facing the same issue.

like image 583
nitte93 Avatar asked Jun 16 '16 04:06

nitte93


2 Answers

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.

like image 116
TheIronDeveloper Avatar answered Oct 22 '22 11:10

TheIronDeveloper


I had the same issue with the app created using create-react-app and what I did to solve this, is I went to Settings tab of my app page in Heroku, then in Buildpacks section I added: https://buildpack-registry.s3.amazonaws.com/buildpacks/mars/create-react-app.tgz as a buildpack.

like image 1
Piotr Kowalski Avatar answered Oct 22 '22 10:10

Piotr Kowalski