webpack-cli icon indicating copy to clipboard operation
webpack-cli copied to clipboard

[Bug]: Cannot find module 'webpack'

Open jesperlandmer opened this issue 8 years ago • 94 comments

Do you want to request a feature or report a bug? Bug

What is the current behavior? Whenever I try to run webpack, I get this error message:

`vagrant@vagrant-ubuntu-trusty-32:/vagrant$ webpack
/usr/lib/node_modules/webpack-cli/bin/webpack.js:237
                                throw err;
                                ^

Error: Cannot find module 'webpack'
    at Function.Module._resolveFilename (module.js:538:15)
    at Function.Module._load (module.js:468:25)
    at Module.require (module.js:587:17)
    at require (/usr/lib/node_modules/webpack-cli/node_modules/v8-compile-cache/v8-compile-cache.js:159:20)
    at Object.<anonymous> (/vagrant/webpack.config.tsx:1:77)
    at Module._compile (/usr/lib/node_modules/webpack-cli/node_modules/v8-compile-cache/v8-compile-cache.js:178:30)
    at Object.Module._extensions..js (module.js:654:10)
    at Module.load (module.js:556:32)
    at tryModuleLoad (module.js:499:12)
    at Function.Module._load (module.js:491:3)
    at Module.require (module.js:587:17)
    at require (/usr/lib/node_modules/webpack-cli/node_modules/v8-compile-cache/v8-compile-cache.js:159:20)
    at WEBPACK_OPTIONS (/usr/lib/node_modules/webpack-cli/bin/convert-argv.js:133:13)
    at requireConfig (/usr/lib/node_modules/webpack-cli/bin/convert-argv.js:135:6)
    at /usr/lib/node_modules/webpack-cli/bin/convert-argv.js:142:17
    at Array.forEach (<anonymous>)
    at module.exports (/usr/lib/node_modules/webpack-cli/bin/convert-argv.js:140:15)
    at yargs.parse (/usr/lib/node_modules/webpack-cli/bin/webpack.js:234:39)
    at Object.parse (/usr/lib/node_modules/webpack-cli/node_modules/yargs/yargs.js:539:18)
    at /usr/lib/node_modules/webpack-cli/bin/webpack.js:212:8
    at Object.<anonymous> (/usr/lib/node_modules/webpack-cli/bin/webpack.js:504:3)
    at Module._compile (module.js:643:30)
    at Object.Module._extensions..js (module.js:654:10)
    at Module.load (module.js:556:32)
    at tryModuleLoad (module.js:499:12)
    at Function.Module._load (module.js:491:3)
    at Module.require (module.js:587:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/usr/lib/node_modules/webpack/bin/webpack.js:12:2)
    at Module._compile (module.js:643:30)

If the current behavior is a bug, please provide the steps to reproduce. I'm using Vagrant, and just installed webpack and webpack cli globally. Using:

node.js: v8.9.4 npm: v5.6.0 webpack: v4.0.1 webpack-cli: v2.0.9

What is the expected behavior? To bundle the files

Please mention other relevant information such as the browser version, Node.js version, Operating System and programming language. I'm using Typescript and React on a Node machine. Vagrant runs on Ubuntu

jesperlandmer avatar Mar 01 '18 12:03 jesperlandmer

I have a similar problem:

TypeError: Cannot read property 'presetToOptions' of undefined

Described by someone else on StackOverflow

ghost avatar Mar 01 '18 13:03 ghost

@andriibyk-apiko what version are you on?

evenstensberg avatar Mar 01 '18 14:03 evenstensberg

@ev1stensberg

"webpack": "^4.0.1",
"webpack-cli": "^2.0.9"

ghost avatar Mar 01 '18 14:03 ghost

Mind printing your prefix paths?

evenstensberg avatar Mar 01 '18 14:03 evenstensberg

Could you do a console log before the error throws on webpack?

evenstensberg avatar Mar 01 '18 14:03 evenstensberg

Also had the same problem with "presetToOptions" as @andriibyk-apiko, but then I reinstalled webpack and then I got this error instead. Installed Webpack v.^2.0.0 instead and now it works.

Don't know what prefix paths is

jesperlandmer avatar Mar 01 '18 16:03 jesperlandmer

npm config get prefix

evenstensberg avatar Mar 01 '18 20:03 evenstensberg

Mind printing your prefix paths?

/usr

ghost avatar Mar 02 '18 07:03 ghost

Mind printing your prefix paths?

C:\Users\<user>\AppData\Roaming\npm

[email protected] (global) [email protected] (local)

Stacktrace:
C:\Users\<user>\AppData\Roaming\npm\node_modules\webpack-cli\bin\webpack.js:237
                            throw err;
Error: Cannot find module 'webpack'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.require (module.js:497:17)
    at require (C:\Users\<user>\AppData\Roaming\npm\node_modules\webpack-cli\node_modules\v8-compile-cache\v8-compile-cache.js:159:20)
    at Object.<anonymous> (C:\Users\<user>\AppData\Roaming\npm\node_modules\webpack-cli\bin\convert-argv.js:7:42)
    at Module._compile (C:\Users\<user>\AppData\Roaming\npm\node_modules\webpack-cli\node_modules\v8-compile-cache\v8-compile-cache.js:178:30)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at yargs.parse.err (C:\Users\<user>\AppData\Roaming\npm\node_modules\webpack-cli\bin\webpack.js:234:14)
    at Object.parse (C:\Users\<user>\AppData\Roaming\npm\node_modules\webpack-cli\node_modules\yargs\yargs.js:539:18)
    at C:\Users\<user>\AppData\Roaming\npm\node_modules\webpack-cli\bin\webpack.js:212:8
    at Object.<anonymous> (C:\Users\<user>\AppData\Roaming\npm\node_modules\webpack-cli\bin\webpack.js:504:3)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (C:\<source-path>\node_modules\webpack\bin\webpack.js:12:2)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.runMain (module.js:604:10)

ashclarke avatar Mar 02 '18 12:03 ashclarke

This might be hard for me to reproduce, anyone from @webpack/core-team that can?

evenstensberg avatar Mar 02 '18 13:03 evenstensberg

@ev1stensberg - Not sure it helps, but it seems to only affect the global install.

I installed webpack-cli locally and it works, but you get the "prefer global" warning.

ashclarke avatar Mar 02 '18 14:03 ashclarke

use $ webpack-cli init

imjar avatar Mar 05 '18 10:03 imjar

@ashclarke that might be cause our prefer to global is wrong ( I think ), will investigate.

evenstensberg avatar Mar 05 '18 11:03 evenstensberg

@jesperlandmer @ashclarke Can you output npm root -g?

Related PR #332.

dhruvdutt avatar Mar 11 '18 19:03 dhruvdutt

@dhruvdutt - C:\Users\<user>\AppData\Roaming\npm\node_modules

ashclarke avatar Mar 12 '18 16:03 ashclarke

Can you try updating?

evenstensberg avatar Mar 12 '18 19:03 evenstensberg

Not sure if this is related, but if you run npm i here https://github.com/quantumjs/solar-popup/tree/master/demo

Then run webpack-cli I get

                                throw err;
                                ^

Error: Cannot find module 'webpack'

Webpack was running as normal when using webpack 3

quantuminformation avatar Mar 20 '18 19:03 quantuminformation

@QuantumInformation You missed installing webpack-cli. Just do npm i -D webpack-cli inside your demo dir and you're set. :100:

dhruvdutt avatar Mar 20 '18 20:03 dhruvdutt

Many thanks for this!

quantuminformation avatar Mar 20 '18 20:03 quantuminformation

Is this issue still valid?

ematipico avatar Mar 20 '18 22:03 ematipico