Error: Cannot find module 'webpack'

后端 未结 17 1948
一整个雨季
一整个雨季 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:41

    On windows, I have observed that this issue shows up if you do not have administrative rights (i.e., you are not a local administrator) on the machine.

    As someone else suggested, the solution seems to be to install locally by not using the -g hint.

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

    Link globally installed package to your project

    npm link webpack
    
    0 讨论(0)
  • 2020-12-22 17:44

    For Visual Studio users: Right click on the npm folder and "Restore Packages".

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

    Just found out that using Atom IDE terminal did not install dependencies locally (probably a bug or just me). Installing git bash externally and running npm commands again worked for me

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

    I had a ton of issues getting a very simple .NET Core 2.0 application to build in VS 2017. This is the error from AppVeyor, however it was essentially the same thing locally (some paths omitted for security) :

    Performing first-run Webpack build...

    module.js:327 throw err;

    EXEC : error : Cannot find module '......../node_modules/webpack/bin/webpack.js'

    at Function.Module._resolveFilename (module.js:325:15)

    at Function.Module._load (module.js:276:25)

    at Function.Module.runMain (module.js:441:10)

    at startup (node.js:140:18)

    at node.js:1043:3

    csproj(25,5): error MSB3073: The command "node node_modules/webpack/bin/webpack.js --config webpack.config.vendor.js" exited with code 1.

    Build FAILED.

    I stumbled upon this question and answer, and I noticed my local instance also had the same warning sign over the {Project Root} -> Dependencies -> npm folder. Right clicking and hitting "Restore packages" got everything loaded up properly, and I was able to build successfully.

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

    Seems to be a common Windows problem. This fixed it for me:

    Nodejs cannot find installed module on Windows?

    "Add an environment variable called NODE_PATH and set it to %USERPROFILE%\Application Data\npm\node_modules (Windows XP), %AppData%\npm\node_modules (Windows 7), or wherever npm ends up installing the modules on your Windows flavor. To be done with it once and for all, add this as a System variable in the Advanced tab of the System Properties dialog (run control.exe sysdm.cpl,System,3)."

    Note that you can't actually use another environment variable within the value of NODE_PATH. That is, don't just copy and paste that string above, but set it to an actual resolved path like C:\Users\MYNAME\AppData\Roaming\npm\node_modules

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