Webpack Error on Heroku Deployment

Error: Cannot find module 'webpack' when deploying to heroku

Move webpack (and any other tools you rely on for building your Heroku slug from "devDependencies" to "dependencies" in your package.json.

You should also be able to call it with just plain "webpack" instead of ./node_modules/.bin/webpack.

By default, "devDependencies" only get installed in node_modules on Dev platforms, whereas Heroku is defined as a production platform.

Heroku error: Cannot find module webpack

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.

When trying to push application to Heroku, I receive a Webpack error about version 5

So i found the solution to my own problem. I changed 'react-scripts' from version 5.0.1 to version 4.0.3, then I did a npm install to change anything due to this version change and it worked! I did this step previously but it did not work but this time I did a npm install after version change which fixed it.

Error in deploying on heroku, /bin/sh: 1: webpack: not found

Try this:

heroku config:set NPM_CONFIG_PRODUCTION=false

Then, in your package.json, replace the "postinstall" you have under "scripts" with this:

"heroku-postbuild": "webpack --config webpack.prod.js",

For other options, see Hosting a production React app built with Wepback on Heroku.



Related Topics



Leave a reply



Submit