[Bug]: Cannot find module 'webpack'
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
I have a similar problem:
TypeError: Cannot read property 'presetToOptions' of undefined
Described by someone else on StackOverflow
@andriibyk-apiko what version are you on?
@ev1stensberg
"webpack": "^4.0.1",
"webpack-cli": "^2.0.9"
Mind printing your prefix paths?
Could you do a console log before the error throws on webpack?
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
npm config get prefix
Mind printing your
prefixpaths?
/usr
Mind printing your
prefixpaths?
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)
This might be hard for me to reproduce, anyone from @webpack/core-team that can?
@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.
use $ webpack-cli init
@ashclarke that might be cause our prefer to global is wrong ( I think ), will investigate.
@jesperlandmer @ashclarke Can you output npm root -g?
Related PR #332.
@dhruvdutt - C:\Users\<user>\AppData\Roaming\npm\node_modules
Can you try updating?
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 You missed installing webpack-cli. Just do npm i -D webpack-cli inside your demo dir and you're set. :100:
Many thanks for this!
Is this issue still valid?