Pls someone explain this to me. I want to use the command npm run build to call webpack. So I modify the script in file package.json. But it did not work. I am using linux
This is my package.json file
{
"name": "learn-webpack",
"version": "1.0.0",
"description": "Learn Webpack",
"main": "index.js",
"scripts": {
"build": "webpack"
},
"author": "",
"license": "ISC",
"devDependencies": {
"babel-core": "^6.26.0",
"babel-loader": "^7.1.4",
"babel-preset-env": "^1.6.1",
"css-loader": "^0.28.11",
"style-loader": "^0.20.3",
"webpack": "^4.2.0"
}
}
This is the error, it already installed cli but it keep send this message
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
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! learn-webpack@1.0.0 build: `webpack`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the learn-webpack@1.0.0 build script.
npm ERR! This is probably not a problem with npm.
There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/huong/.npm/_logs/2018-03-27T14_09_22_103Z-debug.log
Follow the instructions
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
Just run:
npm install webpack-cli -D -g
-g
for good measure, then try running build again and it should work :)
You didn't install webpack-cli into your devDependencies
npm install webpack-cli -D
Actually should solve your problem
Maybe you installed webpack-cli globally, but it's not in your devDependencies
If you are calling a function directly like
"scripts": {
"build": "webpack"
},
Webpack is searched as a command from your $PATH. Using npm install webpack-cli -D
installs it not globally under a $PATH but locally under ./node_modules
.
Therefore you have 2 choices:
npm -gi webpack-cli
node_modules/<path to webpack>
如果将webpack安装到项目中而不是全局安装,请尝试以下操作:
"build": "./node_modules/webpack/bin/webpack"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.