简体   繁体   中英

webpack: command not found after npm install webpack -g

Weird behaviour on my OSX Yosemite: from one day to another all my node modules installed by npm install -g were not found via the Terminal.

I'm not sure if this is due to my node v4.0.0 install the day before.

Try this

echo $(npm config get prefix)/bin

you will get STRING, which should include to your .bash_profile such way

export PATH=$PATH:STRING

我最后还使用NVM进行多个NodeJS版本管理,一切都恢复了控制。

Install it globally

npm i -g webpack

If you will work with webpack, install webpack-dev-server too

npm i -g webpack-dev-server

After I Install this two command I also found errors when run the

webpack

command so I figure out the problem by changing the version of webpack so I Install

npm install webpack@2.1.0-beta.22

and every thing work fine for me.

I recommend you first learn a bit about npm and then webpack . You will struggle a lot. but finally you will find the right destination.

Webpack is in your ./node_modules/.bin/ folder so instead of giving just webpack as the command try this.

./node_modules/.bin/webpack

You have the npm bin command to get the folder where npm will install executables.

You can use the scripts property of your package.json to use webpack from this directory which will be exported.

"scripts": {   "scriptName": "webpack --config etc..." } For example:
"scripts": {   "build": "webpack --config webpack.config.js" } You can

then run it with:

npm run build Or even with arguments:

npm run build -- <args>

This allow you to have you webpack.config.js in the root folder of your project without having webpack globally installed or having your webpack configuration in the node_modules folder.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM