Issues with npm and webpack-cli

Trying to run webpack as part of my build step fails, gives an error that the cli isn’t installed. Using the shell and trying to install the webpack-cli manually results in:

CLI for webpack must be installed.
webpack-cli (https://github.com/webpack/webpack-cli)

We will use "npm" to install the CLI via "npm install -D webpack-cli".
Do you want to install 'webpack-cli' (yes/no): yes

Installing 'webpack-cli' (running 'npm install -D webpack-cli')...
npm ERR! code ENOLOCAL
npm ERR! Could not install from "node_modules/webpack-cli" as it does not contain a package.json file.

webpack-cli is part of my package.json file but isn’t being installed automatically.

Hey there- could you share with me what your build command looks like, and where your service is calling webpack initially? Please feel free to DM me if you’d prefer to not publicly post that on a forum.

My initial thought here is that it should use webpack rather than webpack-cli if it’s being called from something like a package.json build script, which should avoid the problem.

1 Like

Thank you! I was calling webpack from my build shell script instead of calling it from npm run build. Oops! :man_facepalming:t2:

1 Like

Hi I’m having the same issue, but not able to resolve it.

my build script is "build": "webpack"
and this is failing with the same error like in description of this issue.

Any ideas how to solve this?

Fixed it, problem was that I wasn’t installing dependencies before I run build.
Sometimes reading docs twice helps :smile:

Hi! I’m having the same issue, could you tell me how to install dependencies before running build?

Hi Agustin,

I think if you edit the Render build command to: npm install; npm run build
it will install dependencies prior to building. I had the same issue with webpack cli not installed and this fixed it for me.