Error: Cannot find module 'webpack'

后端 未结 17 1947
一整个雨季
一整个雨季 2020-12-22 16:49

I\'m just getting started with webpack and am having difficulty getting the multiple-entry-points sample to build. The webpack.config.js file in the example includes the li

相关标签:
17条回答
  • 2020-12-22 17:26

    I was having this issue on OS X and it seemed to be caused by a version mismatch between my globally installed webpack and my locally installed webpack-dev-server. Updating both to the latest version got rid of the issue.

    0 讨论(0)
  • 2020-12-22 17:26

    for me, it is a wrong error feedback.

    there was config error in webpack.config.js,

    delete the file and start over solved my issue

    0 讨论(0)
  • 2020-12-22 17:27

    If you have installed a node package and are still getting message that the package is undefined, you might have an issue with the PATH linking to the binary. Just to clarify a binary and executable essentially do the same thing, which is to execute a package or application. ei webpack... executes the node package webpack.

    In both Windows and Linux there is a global binary folder. In Windows I believe it's something like C://Windows/System32 and in Linux it's usr/bin. When you open the terminal/command prompt, the profile of it links the PATH variable to the global bin folder so you are able to execute packages/applications from it.

    My best guess is that installing webpack globally may not have successfully put the executable file in the global binary folder. Without the executable there, you will get an error message. It could be another issue, but it is safe to say the that if you are here reading this, running webpack globally is not working for you.

    My resolution to this problem is to do away with running webpack globally and link the PATH to the node_module binary folder, which is /node_modules/.bin.

    WINDOWS: add node_modules/.bin to your PATH. Here is a tutorial on how to change the PATH variable in windows.

    LINUX: Go to your project root and execute this...

    export PATH=$PWD/node_modules/.bin:$PATH 
    

    In Linux you will have to execute this command every time you open your terminal. This link here shows you how to make a change to your PATH variable permanent.

    0 讨论(0)
  • 2020-12-22 17:31

    I solved the same problem by reinstalling, execute these commands

    rm -Rf node_modules
    rm -f package-lock.json
    npm install
    

    rmis always a dangerous command, especially with -f, please notice that before executing it!!!!!

    0 讨论(0)
  • 2020-12-22 17:31

    Installing both webpack and CLI globally worked for me.

    npm i -g webpack webpack-cli
    
    0 讨论(0)
  • 2020-12-22 17:34

    Run below commands in Terminal:

    npm install --save-dev webpack

    npm install --save-dev webpack-dev-server

    0 讨论(0)
提交回复
热议问题