We also ran into this problem, and I like all the answers that suggest using the script defined in package.json .
For our decisions, we often use the following sequence:
npm install --save-dev webpack-cli (if you use webpack v4 or later, otherwise use npm install --save-dev webpack , see npm install --save-dev webpack package , received January 19, 2019 )npx webpack
Step 1 is one-time. Step 2 also checks ./node_modules/.bin . You can also add the second step as an npm script in package.json , for example:
{ ... "scripts": { ... "build": "npx webpack --mode development", ... }, ... }
and then use npm run build to execute this script.
I tested this solution with version npm 6.5.0, version webpack 4.28.4, and version webpack-cli 3.2.1 on Windows 10 by running all the commands inside the PowerShell window. My version of nodejs / was 10.14.2. I also tested this on Ubuntu Linux version 18.04.
I would not recommend installing web packages globally, especially if you work with many different projects, each of which may require a different version of the web package. Installing a web package globally blocks access to a specific version in all projects on the same computer.
Manfred Jan 18 '19 at 20:01 2019-01-18 20:01
source share