1. 程式人生 > 其它 >npm安裝webpack無反應_...install 'webpack-cli' to use webpack via CLI問題

npm安裝webpack無反應_...install 'webpack-cli' to use webpack via CLI問題

技術標籤:npm安裝webpack無反應

npm 安裝 webpack 4:

npm install webpack --save-dev
npm install webpack-cli --save-dev

安裝完,執行webpack -v命令出現以下提示

One CLI for webpack must be installed. These are recommended choices, delivered as separate packages:
 - webpack-cli (https://github.com/webpack/webpack-cli)
   The original webpack full-featured CLI.
We will use "npm" to install the CLI via "npm install -D".
Do you want to install 'webpack-cli' (yes/no): no
You need to install 'webpack-cli' to use webpack via CLI.
You can also install the CLI manually.

解決辦法:

//使用全域性的方式安裝webpack-cli
npm install webpack-cli -g

原因:

如果你webpack和webpack-cli是區域性安裝的,想要使用webpack命令必須進入node_modules/.bin/webpack才能執行webpack命令,.bin目錄包含的是一系列可以執行的命令,但是如果你是全域性安裝的webpack-cli,就不需要進入bin目錄,webpack就能夠尋找到它的命令路徑了。