3
votes

so I'm new to React and wanted to start on a simple practice project. I'm following a tutorial that uses Webpack. I've installed Webpack in my working directory and globally using npm over Windows command. I set up a webpack.config.js file, included webpack as a devDependency in my package.json file, and added it to my scripts. Here is my package.json file:

{
  "name": "reactproj",
  "version": "1.0.0",
  "description": "A tutorial project for React js",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "webpack --config webpack.config.js"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {},
  "devDependencies": {
    "webpack": "^4.1.1",
    "webpack-cli": "^2.0.10"
  }
}

However, when I run the webpack command on the Windows cli, I get a response saying this:

The CLI moved into a separate package: webpack-cli.
Please install 'webpack-cli' in addition to webpack itself to use the CLI.
-> When using npm: npm install webpack-cli -D
-> When using yarn: yarn add webpack-cli -D

So I install the webpack-cli module using the npm command. It install with a few warnings about outdated Babel modules etc, but installs successfully. So I try the webpack command again in my Windows cli. I get the same response about webpack-cli. I try the webpack-cli command, and I get:

'webpack-cli' is not recognized as an internal or external command,
operable program or batch file.

What am I doing wrong here? Why can't I get webpack to work? Both webpack and the cli modules are located in the node_modules file, so I'm pretty sure they're actually there.

2

2 Answers

3
votes

It's most likely due to your Path variable not being set.

You could try and install it globally: npm install webpack-cli -g

or try adding npm to your Path variable

c:\Users\yourname\AppData\Roaming\npm\

0
votes

npx webpack runs the Webpack binary that's in your project's node_modules folder. Unlike the global installation, it just works.