webpack is not recognized as a internal or externa

2020-01-26 04:17发布

I am Learning React.js and i am using windows 8 OS.i have navigate to my root folder

1.Created the package.json file by npm init
2. install webpack by npm install -S webpack.now webpack has been downloaded to my modules folder
3. install webpack globally by typing npm install webpack -g
4. i am also having a webpack.config.js in my root folder which contains the source and ouput directory
5. when i type the webpack command i am getting the below error.

webpack is not recognized as a internal or external command,operable program or batch file

标签: npm webpack
22条回答
欢心
2楼-- · 2020-01-26 04:47

npm install -g webpack-dev-server will solve your issue

查看更多
戒情不戒烟
3楼-- · 2020-01-26 04:47

Webpack CLI is now in a separate package and must be installed globally in order to use the 'webpack' command:

npm install -g webpack-cli

EDIT: Much has changed. Webpack folks do not recommend installing the CLI globally (or separately for that matter). This issue should be fixed now but the proper install command is:

npm install --save-dev webpack

This answer was originally intended as a "work-around" for the OPs problem.

查看更多
Animai°情兽
4楼-- · 2020-01-26 04:47

I've had same issue and just added the code block into my package.json file;

 "scripts": {
   "build": "webpack -d --progress --colors"
 }

and then run command on terminal;

npm run build
查看更多
Juvenile、少年°
5楼-- · 2020-01-26 04:47

Just run your command line (cmd) as an administrator.

查看更多
Fickle 薄情
6楼-- · 2020-01-26 04:47

I had this issue when upgrading to React 16.12.0.

I had two errors one regarding webpack and the other regarding the store when rendering the DOM.

Webpack Error:

webpack is not recognized as a internal or external command,operable program or batch file

Webpack Solution:

  1. Close related VS Solution
  2. Delete node_modules folder
  3. Deleted package-lock.json
  4. npm install
  5. npm rebuild
  6. Repeated this 2-3 times

Store Error:

Type Store<()> is not assignable to type Store<any, AnyAction>

Store Solution:

Suggestions to update my React version didn't fix this error for me, but irrespective I would recommend doing it.

My code ended up looking like this:

ReactDOM.render(
        <Provider store={store as any}>
            <ConnectedApp />
        </Provider>,
        document.getElementById('app')
    );

As per this solution

查看更多
Explosion°爆炸
7楼-- · 2020-01-26 04:48

As an alternative, if you have Webpack installed locally, you can explicitly specify where Command Prompt should look to find it, like so:

node_modules\.bin\webpack

(This does assume that you're inside the directory with your package.json and that you've already run npm install webpack.)

查看更多
登录 后发表回答