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
```/Users/nikos/.nvm/versions/node/v9.2.0/lib/node_modules/webpack-cli/bin/webpack.js:242
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?
Friendly ping @jesperlandmer
Don’t know! I think the main issue has to do with Vagrant and how Vagrant handles global values. I had several problems with other dependencies as well (e.g. Firebase). Staying with docker from now on
Okay. Let's keep this open for others to come to if they have similar issues!
Same issue with the global install.
npm install -g webpack-cli and running webpack-cli throws:
•100% ➜ webpack-cli
/usr/local/lib/node_modules/webpack-cli/bin/webpack.js:242
throw err;
^
Error: Cannot find module 'webpack'
at Function.Module._resolveFilename (module.js:543:15)
at Function.Module._load (module.js:470:25)
at Module.require (module.js:593:17)
at require (/usr/local/lib/node_modules/webpack-cli/node_modules/v8-compile-cache/v8-compile-cache.js:159:20)
at Object.<anonymous> (/usr/local/lib/node_modules/webpack-cli/bin/convert-argv.js:7:24)
at Module._compile (/usr/local/lib/node_modules/webpack-cli/node_modules/v8-compile-cache/v8-compile-cache.js:178:30)
at Object.Module._extensions..js (module.js:660:10)
at Module.load (module.js:561:32)
at tryModuleLoad (module.js:501:12)
at Function.Module._load (module.js:493:3)
at Module.require (module.js:593:17)
at require (internal/module.js:11:18)
at yargs.parse (/usr/local/lib/node_modules/webpack-cli/bin/webpack.js:239:14)
at Object.parse (/usr/local/lib/node_modules/webpack-cli/node_modules/yargs/yargs.js:543:18)
at /usr/local/lib/node_modules/webpack-cli/bin/webpack.js:217:8
at Object.<anonymous> (/usr/local/lib/node_modules/webpack-cli/bin/webpack.js:512:3)
at Module._compile (module.js:649:30)
at Object.Module._extensions..js (module.js:660:10)
at Module.load (module.js:561:32)
at tryModuleLoad (module.js:501:12)
at Function.Module._load (module.js:493:3)
at Function.Module.runMain (module.js:690:10)
at startup (bootstrap_node.js:194:16)
at bootstrap_node.js:666:3
Actually happens with the local setup as well:
npm install --dev webpack-cli and webpack-cli throws
•100% ➜ webpack-cli
undefined
/Users/okonet/Projects/kleiner_perkins/crm_web_client/node_modules/webpack-cli/bin/webpack.js:242
throw err;
^
TypeError: validateSchema is not a function
at processConfiguredOptions (/Users/okonet/Projects/kleiner_perkins/crm_web_client/node_modules/webpack-cli/bin/convert-argv.js:156:48)
at module.exports (/Users/okonet/Projects/kleiner_perkins/crm_web_client/node_modules/webpack-cli/bin/convert-argv.js:150:10)
at yargs.parse (/Users/okonet/Projects/kleiner_perkins/crm_web_client/node_modules/webpack-cli/bin/webpack.js:239:39)
at Object.parse (/Users/okonet/Projects/kleiner_perkins/crm_web_client/node_modules/webpack-cli/node_modules/yargs/yargs.js:543:18)
at /Users/okonet/Projects/kleiner_perkins/crm_web_client/node_modules/webpack-cli/bin/webpack.js:217:8
at Object.<anonymous> (/Users/okonet/Projects/kleiner_perkins/crm_web_client/node_modules/webpack-cli/bin/webpack.js:512:3)
at Module._compile (module.js:649:30)
at Object.Module._extensions..js (module.js:660:10)
at Module.load (module.js:561:32)
at tryModuleLoad (module.js:501:12)
at Function.Module._load (module.js:493:3)
at Function.Module.runMain (module.js:690:10)
at startup (bootstrap_node.js:194:16)
at bootstrap_node.js:666:3
I think it's related to the webpack version. I'm installing CLI to migrate the project from 1.x to 4.x and I see this
warning " > [email protected]" has incorrect peer dependency "webpack@^4.0.0".
I'm not sure why it is even installing it in this case...
Downgrading to 1.x doesn't help either:
npm install --dev [email protected] && webpack-cli throws:
•100% ➜ webpack-cli
module.js:545
throw err;
^
Error: Cannot find module 'webpack/lib/ErrorHelpers'
at Function.Module._resolveFilename (module.js:543:15)
at Function.Module._load (module.js:470:25)
at Module.require (module.js:593:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/Users/okonet/Projects/kleiner_perkins/crm_web_client/node_modules/webpack-cli/bin/webpack.js:11:20)
at Module._compile (module.js:649:30)
at Object.Module._extensions..js (module.js:660:10)
at Module.load (module.js:561:32)
at tryModuleLoad (module.js:501:12)
at Function.Module._load (module.js:493:3)
and
•100% ➜ la ./node_modules/webpack/lib/ | grep Error
-rw-r--r-- 1 okonet staff 487B Feb 22 2016 ChunkRenderError.js
-rw-r--r-- 1 okonet staff 487B Feb 22 2016 EntryModuleNotFoundError.js
-rw-r--r-- 1 okonet staff 518B Feb 22 2016 ModuleNotFoundError.js
-rw-r--r-- 1 okonet staff 977B Feb 22 2016 ModuleParseError.js
-rw-r--r-- 1 okonet staff 524B Feb 22 2016 NoErrorsPlugin.js
What environment is it? I can't reproduce it locally. :thinking:
Also, make sure when you do webpack-cli --dev, you run it with npx webpack-cli else it might get resolved from your global node_modules.
@dhruvdutt the problem goes away after installing webpack@4 (I guess anything greater than 1) and weback-cli locally in the project.
@dhruvdutt I just tried with npx and webpack@4 installed:
npx webpack-cli migrate ./webpack/homebase/webpack.development.js
npx: installed 489 in 19.386s
Cannot find module 'webpack'
Can you make a reproducible demo(zip) along with steps?
I think there's something wrong with the installation or running of commands.
@okonet @dhruvdutt I'm running into this issue as well.
Cannot find module 'webpack'
It seems this issue is caused by webpack.development.js not being able to find my local npm_modules version of webpack. I think this is the case because when I run webpack without --config it runs, although it does throw an unrelated compile error. However, when I look in node_modules webpack is missing, despite running npm install webpack -D.
Maybe something fishy with how the cli resolves, I'll check it out
Same problem here on Ubuntu 17. Should we install locally instead of globally ? Might be the temporary fix...
Could you try to install [email protected]? Does the error persist?
npx webpack or CLI doesn't work, maybe @zkat has some tips regarding using IIFE & prefering locally installed packages? The error is from here: https://github.com/webpack/webpack-cli/blob/master/bin/webpack.js#L11-L15
I was having the same issue in Docker, but only on Mac and Linux. Windows was fine.
As a temporary fix, I have had to add webpack and webpack-cli to the "dependencies" section in package.json (rather than just the devDependencies section).
I tried many different combinations in the dockerfile to install webpack during the build, but none of them worked except for this.
I was getting the same error described in the initial comment. (I'm using a mac with webpack version ^4.5.0 and webpack-cli version ^2.0.14)
I tried a few things all of which didn't work for me:
1) Used the global version of webpack + webpack-cli (uninstalling the local copies)
2) Adding webpack + webpack-cli to the "devDependencies" section of my package.json and uninstalling the global versions.
3) Adding webpack + webpack-cli to the "dependencies" section of my package.json and uninstalling the global versions.
Ultimately, I managed to get around the issue with the following steps:
1) I uninstalled node completely, then reinstalled it again - version 9.11.1
2) I added webpack + webpack-cli to the "dependencies" section of my package.json.
3) I removed these lines from my webpack.config.js:
devServer: { hot: true },
plugins: [ new webpack.HotModuleReplacementPlugin() ]
4) I now bundle my project with webpack by using the local version with the following command in the root directory of my project:
node_modules/.bin/webpack
I had this happen, similar to the experience here: https://github.com/webpack/webpack-cli/issues/299#issuecomment-376839242
TLDR: Make sure webpack + webpack-cli are installed, rm -rf node_modules, and reinstall. worked in my case. (yours may very)
I use yarn. And yarn workspaces.
But the gist of it is I made sure webpack and webpack-cli were both in package.json. 4.5.0 and 2.0.14 worked for me. Locally installed (not npm i -g)
I invoke webpack via ./node_modules/.bin/webpack (normal for me, since 3.x)
And, when this error happened, I just rm -rf node_modules (in all descendant workspace projects, too. e.g. rm -rf ./workspacea/node_modules) and reinstalled again via $ yarn. This wiped away whatever cruft was there before. That's what made it work for me.
Also if you're troubleshooting: double check to make sure you pick one or the other: a locally installed webpack+webpack-cli, or a system one. If you go local, sure you wipe out [sudo] npm uninstall -g webpack webpack-cli.
(I still don't know whether it's best / wrong / right to use webpack on system's node_modules or local.)
Ran into this myself just now, none of the comments above have helped... Looking for clarification...
-g not recommended ?npm uninstall -g webpack webpack-cli
npm install -g webpack webpack-cli
webpack
Error: Cannot find module 'webpack'
Webpack-cli will try to default to your local installation, which makes the error appear. I'll try to push a fix to this as soon as possible.
I just did npm install and it worked for me
I previously did updated my node and npm, here’s my configuration
Ajmals-MacBook-Pro:React ajmal$ node -v
v9.11.1
Ajmals-MacBook-Pro:React ajmal$ npm -v
5.8.0
Ajmals-MacBook-Pro:React ajmal$ webpack -v
4.5.0
Ajmals-MacBook-Pro:React ajmal$ webpack-cli -v
2.0.14
Ajmals-MacBook-Pro:React ajmal$ npm install
[email protected] install /Users/ajmal/Desktop/Development/React/node_modules/fsevents
node install
[fsevents] Success: "/Users/ajmal/Desktop/Development/React/node_modules/fsevents/lib/binding/Release/node-v59-darwin-x64/fse.node" is installed via remote
npm WARN [email protected] No repository field.
added 405 packages from 314 contributors in 12.995s
Ajmals-MacBook-Pro:React ajmal$ webpack
Hash: ****
Version: webpack 4.5.0
Time: 363ms
Built at: 2018-4-16 14:07:18
Asset Size Chunks Chunk Names
script.min.js 4.71 KiB 0 [emitted] main
Entrypoint main = script.min.js
[0] ./js/scripts.js 0 bytes {0} [built]
WARNING in configuration
The 'mode' option has not been set, webpack will fallback to 'production' for this value. Set 'mode' option to 'development' or 'production' to enable defaults for each environment.
You can also set it to 'none' to disable any default behavior. Learn more: https://webpack.js.org/concepts/mode/
@ajmald Works when you don't sandbox the cli or webpack. Problems are when combined with other tools that rely on symlinks. As mentioned previously, we have an IIFEE for the entire bin file in order to use return inside it without exiting the process.
I'll try to find out what we need to change in order to fix the issue, might take a couple of days though.
Anyone here having a confident reproduction of this error? Could you give me a repository?
As per @tony 's comment, moving to yarn workspaces fixed this issue for me.
Unfortunately the project I was seeing this issue with is not public, so I have no way of sharing, but I can describe it somewhat. My project has the following structure:
project-folder/public/www
project-folder/public/manage
project-folder/other_stuff..
www and manage are both separate javascript (react) projects with their own webpack.config.x.js files and their own package.json files. Up until recently, that hasn't been an issue, but today when I tried to build either one, I was getting the error in this issue in both folders
I did as described in the yarn workspaces doc, and then ran webpack-cli again and it worked just fine for both.
_As a side-note for anyone trying the same, I had to move postcss.config.js to my yarn workspace root. Having it in each workspace (each subdirectory) was throwing all sorts of errors for me. Also, the workspaces property in the root's package.json file have to be named after the subdirectories, not after the subdirectory package.json name properties_
Thanks for the info @enobrev , I'll check it out to see if we can fix the issue! Gonna look into it tomorrow
Could anyone try to run this branch locally in their project? #423 Also, it would be nice if you'd post a path to webpack by adding a console.log here https://github.com/webpack/webpack-cli/blob/836bfae8a0a3a5033576eb47d846509a3cea4e2c/bin/webpack.js#L427
Could you guys try to install [email protected] ?
@ev1stensberg I am receiving an issue which I think _might_ be related to this one. I found an SO about it and after some playing around managed to workaround the issue by NOT installing webpack-cli globally.
At this time I feel like webpack-cli globally only works if webpack is also installed globally? But I'm not absolutely certain about that.
I am using:
"webpack": "^4.8.1",
"webpack-cli": "^2.1.3"
Essentially trying to run the global webpack-cli against the local project results in Cannot find module 'webpack/schemas/WebpackOptions.json'
Please have a look at https://stackoverflow.com/questions/49974837/error-while-running-react-application/50281907 for more details.
Thanks for providing @klick-barakgall !
Thanks @klick-barakgall I was getting the same error, and your explanation solved it for me also.
@ev1stensberg Sorry, but I feel that based on my findings that something is still wrong with webpack-cli. Is this a known issue? Is it being tracked elsewhere? Will you consider reopening this issue?
@klick-barakgall yep, it's this one
@ev1stensberg, apologies I see now this issue is in fact still open. My bad :S.
I have the same problem
And this command works with me:
npm uninstall -g webpack webpack-cli
npm install -g webpack webpack-cli
I have run webpack several times on my project but suddenly throw this Error I tried to install babel-preset-react but throw Error.
Then, i run webpack in project it throws this Error below
module.js:540
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 (internal/module.js:11:18)
at Object.
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)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: webpack-dev-server --mode development --open
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\duntu\AppData\Roaming\npm-cache_logs\2018-05-18T18_41_35_681Z-debug.log
this was the previous error when i tried instal babel-preset-react and webpack middleware
yarn add webpack-dev-middleware babel-preset-react -D
yarn add v1.6.0
[1/4] Resolving packages...
[2/4] Fetching packages...
warning Pattern ["webpack-dev-middleware@^3.1.3"] is trying to unpack in the same destination "C:\Users\duntu\AppData\Local\Yarn\Cache\v1\
pm-webpack-dev-middleware-3.1.3-8b32aa43da9ae79368c1bf1183f2b6cf5e1f39ed" as pattern ["[email protected]"]. This could result in non-deterministic behavior, skipping.
info [email protected]: The platform "win32" is incompatible with this module.
info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
warning " > [email protected]" has incorrect peer dependency "webpack@^3.1.0".
This is probably fixed in #453, thanks for the patience guys ❤️ Closing for now. We're releasing a new version of webpack-cli in a bit, so keep tight, the bug is soon gone 😃
Any news? Still fails in 3.0.8
Do you have a repository where we can check why it's falling? It might be better to open a new issue. This has been closed for a month so we assumed everything was patched. Maybe the issue is caused by something else. If you could open a new issue and provide a valid repro, it will be awesome. Thanks!
It is private, but this changes fixed this issue for me
"scripts": {
- "webpack": "webpack --config='config/webpack.config.js'",
+ "webpack": "webpack-cli --config='config/webpack.config.js'",
Strange. Do you have webpack installed already? try to only have a local installation
Install webpack and webpack-cli in pkg json and your scripts should call webpack on webpack-cli@latest and webpack v4+
Install webpack-cli and yarn add
npm install webpack-cli -D
yarn add webpack-cli -D
probably covered already, but just in case... I'm a new webpack user and I installed webpack globally via npm and I installed webpack-cli within my local project's package.json dependencies. That is when the error was occurring. I uninstalled the local cli and then installed the cli globally. No more error. I think they both need to be in the same environment. This thread helped me figure it out. Thanks!
@preston206 Thanks for sharing. It's quite unfortunate for us that users hit this error though, we use import-local which should resolve this, but it doesn't as webpack and webpack-cli is in two different locations
I have the same problem.
I have uninstalled globally webpack and webpack-cli
Here are the versions I use in my project package.json
"webpack": "^4.16.2",
"webpack-cli": "^3.1.0",
And I still encounter the error whenever i run "npx webpack" or "npx webpack-cli"
Error: Cannot find module 'webpack'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
at Function.Module._load (internal/modules/cjs/loader.js:507:25)
at Module.require(internal/modules/cjs/loader.js:637:17)`
Any other solutions available ?
Doing a refactor of the bin folder and that will solve it. Ready in august/september!
@ev1stensberg any updates? Installing webpack and webpack-cli locally doesn't work for me, and neither does npx webpack or running webpack-cli, and I tried rm -rf node_modules and then reinstall. Until then, what should I do?
I uninstalled globally webpack and webpack-cli and then reinstalled, and it seems to be working so far...
Working on fixing this but haven’t had a lot of spare time lately. Sorry for the inconviniences.. 👨🏼🔧
@ev1stensberg in the meantime, what should I do to follow best practices with my projects?
Anything that runs webpack is viable. Ideal case is to run it through node modules by installing them both locally as devDeps. If that doesn’t work, then look in the issue thread 🤗
@QuantumInformation You missed installing
webpack-cli. Just donpm i -D webpack-cliinside your demo dir and you're set. 💯
Many thanks, it worked!
OP appears to be using Unix, but I had the same error after multiple project restarts/npm installs. For those using WSL / Bash for Windows I noticed sometimes npm install fails to install some of the binaries. Webpack and webpack-dev-server were missing in my case.
ls node_modules/.bin/
// if the binaries are missing run any combo of:
npm i -D webpack webpack-cli webpack-dev-server
// we had to modify our package.json to access the binary with the full path (instead of just npx webpack):
build:dev: "npx ./node_modules/.bin/webpack --config ./webpack.config/service.dev.js --watch",
Spent half a day trying to figure this out and ran through most of the suggestions here, hopefully it helps someone.
I only got it to work by first install npm install -g webpack-cli and then npm install -g webpack.
I only got it to work by first install npm install -g webpack-cli and then npm install -g webpack.
Thanks! This worked for me too!
Note: installing webpack globally is not recommended.
For now I reference it as node_modules/webpack/bin/webpack.js in package.json/scripts section
npm i -D webpack-cli Worked for me.
Same issue, deleting node_modules and package-lock then npm install - worked for me
I only got it to work by first install npm install -g webpack-cli and then npm install -g webpack.
This worked for me in the way that it then did found finally the webpack-cli module but then I got this warnings and error:
WARNING in configuration
The 'mode' option has not been set, webpack will fallback to 'production' for this value. Set 'mode' option to 'development' or 'production' to enable defaults for each environment.
You can also set it to 'none' to disable any default behavior. Learn more: https://webpack.js.org/concepts/mode/
ERROR in multi ./app.js bundle.js
Module not found: Error: Can't resolve 'bundle.js' in '/home/carmine/Desktop/JS/webpack_app'
@ multi ./app.js bundle.js main[1]
I solved my last issue thanks to this : https://stackoverflow.com/questions/49389677/module-not-found-error-cant-resolve-bundle-js-in-users-jonathankuhl-docum
You can try running webpack directly from the node_modules folder, this seems to solve a lot of the red errors in the terminal.
./node_modules/.bin/webpack
And if you don't want to keep typing that line you can add a build script in your package.json file
"scripts": {
"build": "./node_modules/.bin/webpack"
...
Then in the terminal you can just type
npm run build
npm link webpack
npm link webpack-cli
https://stackoverflow.com/questions/29492240/error-cannot-find-module-webpack
Worked for me.
I likely cannot provide much insight but this was affecting me not locally on macOS but on my continuous integration provider linux/Ubuntu, after debugging with SSH in the CI, I found out that webpack-cli 3.2.0 was the first version to introduce this issue, so I downgraded it to 3.1.2 in my package.json:
- "webpack-cli": "3.2.0",
+ "webpack-cli": "3.1.2",
And it worked! I also tried many webpack 4.X and they all seemed to work with cli 3.1.2.
CI debugging data:
Docker Engine Version: 18.09.1
Kernel Version: Linux 31e94c1fa4b9 4.15.0-1035-aws #37-Ubuntu SMP Mon Mar 18 16:15:14 UTC 2019 x86_64 Linux
Starting container node:10.12.0
Have you tried updating to the latest CLI version? Is the issue still persistent?
Yes, i also tried the latest version, forgot to mention it.
On Wed, May 29, 2019, 3:57 AM Even Stensberg notifications@github.com
wrote:
Have you tried updating to the latest CLI version? Is the issue still
persistent?—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/webpack/webpack-cli/issues/299?email_source=notifications&email_token=AAAO4CGJVB5TJRDYZYTXUXLPXYZPXA5CNFSM4ETAZQV2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODWOP67A#issuecomment-496828284,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAAO4CESOUDV7BYUQ54REHDPXYZPXANCNFSM4ETAZQVQ
.
Alright. Aware this is a bug, but the bug is due the fact that you have a global and a local installation or vice versa. Could you try aligning CLI installation location with webpack location?
Hey, got a new machine and I don't have webpack and webpack-cli installed globally; Debugging at the moment but seems that the reports above are correct, the bug still persists; I'll update the comment with more info after I fully understand what's going on.
The following is for a project that has a dependecy
devDependecies: {
"foobar": "git+https://gitlab+deploy-token-1:xxxxx@yyyyyy/foobar.git#vTag",
}
{ Error: Cannot find module 'webpack-cli'
at Function.Module._resolveFilename (module.js:548:15)
at Function.Module._load (module.js:475:25)
at Module.require (module.js:597:17)
at require (internal/module.js:11:18)
at runCommand.then (/Users/punkbit/www/temp1/node_modules/webpack/bin/webpack.js:142:5)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:189:7) code: 'MODULE_NOT_FOUND' }
md5-cacac0edcbbf959e93fce69361afb820
npm list -g --depth 0:
├── [email protected]
└── [email protected]
md5-81201e3e845d12b36bb7c1cb3a066d21
npx webpack -v
One CLI for webpack must be installed. These are recommended choices, delivered as separate packages:
- webpack-cli (https://github.com/webpack/webpack-cli)
The original webpack full-featured CLI.
We will use "npm" to install the CLI via "npm install -D".
Do you want to install 'webpack-cli' (yes/no):
md5-f7f3ac6fcf32b2539067903c38211b4a
which webpack
webpack not found
Fixed after:
https://github.com/webpack/webpack-cli/issues/299#issuecomment-472690048
This worked for me. Once I ran npm link on webpack and webpack-cli it worked after that. No need to not follow best practice and install globally.
i was getting the same error " [Bug]: Cannot find module 'webpack' "
i fixed this Error after following these steps:
Step-1: Run this command to install webpack
npm install --save-dev webpack webpack-cli
Step-2: uninstall Webpack
npm uninstall --save-dev webpack webpack-cli
step-3: Delete node-module folder from your project directory
rm -rf node_modules
step-4: Run npm install
npm install
step-5: Run yarn command
yarn
step-6: Run start command
yarn start
or
npm start
This is working for me









So, I tried about everthing in this thread:
No luck!! Only directly running with node node_modules/webpack-dev-server/bin/webpack-dev-server.js works.
Maybe a bug with > 91 comments is an indication??
Closing due to inactivity. Please test with latest version and feel free to reopen if still regressions. Thanks!
If somebody faced with the problem again please open the new issue with reproducible example, I think we fixed it (please use webpack-cli@4)
i was able to solve this problem in fedora 33 this way:
nvm install 10.23.3 # node version!cd <your node path>rm -Rf node_modules/gedit package.json"webpack": "^4.39.3" to "devDependencies"npm installnpm start
Most helpful comment
I have the same problem
And this command works with me:
npm uninstall -g webpack webpack-cli
npm install -g webpack webpack-cli