Webpack command not found

风格不统一 提交于 2019-12-10 01:21:31

问题


I have installed webpack using

npm install -g webpack

and

npm install webpack 

I also installed webpack-dev-server

npm install -g webpack-dev-server

After completion of installation, I ran the command webpack but, it shows below error

webpack: command not found

I am not getting what is the error.


回答1:


Your webpack exists in ./node_modules/.bin/ folder . So you should execute this command :

./node_modules/.bin/webpack

Check out the answer in this thread .

webpack command not working




回答2:


As a good practice is recommended to install webpack and webpack-dev-server locally, more info here.

yarn add webpack webpack-dev-server --dev
# or
npm install webpack webpack-dev-server --save-dev

Then you can add these lines to your scripts section in your package.json file.

"scripts": {
  "build": "webpack --progress --colors",
  "start": "webpack-dev-server --progress --colors"
}

and finally

npm start
npm run build

Note: You need to have a webpack.config.js in the root folder to make it run correctly.




回答3:


I needed to manually install:

npm install --save-dev webpack-cli

I guess its needed so that Angular CLI actually understands the commands related to Webpack.




回答4:


If you want to use global installation, you can find webpack script in [node_installed_path]/lib/node_modules/webpack/bin/, you can use with absolute path, adding to PATH environment variable, or symbolic link, etc.

If you want to use local installation, find it in ./node_modules/.bin/.

I recommand using local installation (for same reason about babel).



来源:https://stackoverflow.com/questions/44845143/webpack-command-not-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!