Home
Support Forums

Sh: 1: webpack: not found for React deployment

I get webpack not found error for my React Build.

Hi, @RedVelocity. It looks like you resolved the issue now. My best guess is that webpack was missing from package.json and adding the dependency there would resolve the issue.

​Please let us know if there are any questions and also please feel free to share the solution here (if you want to and it might help someone else if you do).

Hey, the issue is not yet resolved. I’ve added workaround in my build script to explicitly install dev dependencies as follows

npm install --only=dev && npm run build

Hey there @RedVelocity!

here is some general guidance contains a ton of useful debugging tips that can likely help you solve your problem :slight_smile: also it would likely be helpful to see your package.json.

Hi, @RedVelocity. I found the root cause of the dependency not installing.

You are causing the devDependencies not to be installed because you are manually setting NODE_ENV to “production” here:

https://app.netlify.com/sites/d-smart/settings/deploys#environment-variables

You told npm not to install the devDependencies. This was a setting you changed manually.

With this environment variable to “production”, it will always prevent npm from installing the devDependencies. This is true anywhere npm is used. It isn’t something specific to Netlify, it is specific to npm.

We talk about that in our documentation here, quoting:

Dependencies and production

If you set the NODE_ENV to production , any devDependencies in your package.json file will not be installed for the build.

This is covered in the npm documentation here:

https://docs.npmjs.com/using-npm/config.html#production

To summarize, the only reason this happened is because you configured the environment variable NODE_ENV="production" which will always cause this behavior on any system running npm. If there are other questions about this, please let us know.

1 Like

Hi Luke,

Makes sense!
Out of curiosity, I was wondering about a couple of things.

  1. The error disappeared when I updated my build script back to just npm run build, does this mean the dev dependencies are permanently cached?
  2. Any frontend app bundled with webpack will have it as a dev dependency to reduce bundle size. I was kind of expecting the dev dependencies to be auto installed even for a production build because this would be quite a common occurrence? unless I’m missing something.

Appreciate your response, thanks!

Hi, @RedVelocity.

The local node_modules directory tree is cached by the build image but it isn’t considered permanent. It can manually be deleted and there can be other reasons which cause it to be deleted between builds.

It is there to help speed up builds when possible but it cannot be treated as persistent (because it isn’t).

The key takeaway is this:

  • We don’t control how npm works and this behavior is 100% controlled by npm alone. This always how npm works with a NODE_ENV="production" environment variable.

The behavior you are seeing has nothing to do with Netlify. In fact, we set NODE_ENV="development" exactly to prevent this behavior. You changed that default by manually setting it to “production” instead.

This tells npm, “Do not install the devDependencies.”

If you want this dependency installed when NODE_ENV="production" then move it to dependencies and don’t put it in devDependencies (or don’t set NODE_ENV="production") .