Cannot find module webpack.mix

See original GitHub issue
  • Node Version (node -v): v7.4.0
  • NPM Version (npm -v): v4.0.5
  • OS: Ubuntu 16

Description:

On production server get an error when running npm run dev or production. On local env works fine. Server is a DO server with forge and Envoyer for deploymemts. I think there is something related to the virtual links.

Error I get is:

node node_modules/cross-env/dist/bin/cross-env.js NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js

module.js:472 throw err; ^

Error: Cannot find module ‘/home/forge/XXXX/storage/app/webpack.mix’ at Function.Module._resolveFilename (module.js:470:15) at Function.Module._load (module.js:418:25) at Module.require (module.js:498:17) at require (internal/module.js:20:19) at Mix.initialize (/home/forge/pitz.es/storage/app/node_modules/laravel-mix/src/Mix.js:45:9) at Object.<anonymous> (/home/forge/pitz.es/storage/app/node_modules/laravel-mix/setup/webpack.config.js:18:5) at Module._compile (module.js:571:32) at Object.Module._extensions…js (module.js:580:10) at Module.load (module.js:488:32) at tryModuleLoad (module.js:447:12) at Function.Module._load (module.js:439:3) at Module.require (module.js:498:17) at require (internal/module.js:20:19) at requireConfig (/home/forge/pitz.es/storage/app/node_modules/webpack/bin/convert-argv.js:96:18) at /home/forge/pitz.es/storage/app/node_modules/webpack/bin/convert-argv.js:109:17 at Array.forEach (native)

npm ERR! Linux 4.4.0-57-generic npm ERR! argv “/usr/local/bin/node” “/usr/local/bin/npm” “run” “dev” npm ERR! node v7.4.0 npm ERR! npm v4.0.5 npm ERR! code ELIFECYCLE npm ERR! pitz@1.0.0 dev: node node_modules/cross-env/dist/bin/cross-env.js NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the pitz@1.0.0 dev script ‘node node_modules/cross-env/dist/bin/cross-env.js NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js’. npm ERR! Make sure you have the latest version of node.js and npm installed. npm ERR! If you do, this is most likely a problem with the pitz package, npm ERR! not with npm itself. npm ERR! Tell the author that this fails on your system: npm ERR! node node_modules/cross-env/dist/bin/cross-env.js NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js npm ERR! You can get information on how to open an issue for this project with: npm ERR! npm bugs pitz npm ERR! Or if that isn’t available, you can get their info via: npm ERR! npm owner ls pitz npm ERR! There is likely additional logging output above.

Steps To Reproduce:

npm run dev

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:22 (1 by maintainers)

github_iconTop GitHub Comments

30reactions
JeffreyWaycommented, Mar 7, 2017

Mix needs to have a webpack.mix.js file in the project root, so if it can’t find one, it makes sense that it will fail. I don’t think there’s anything we can do to this repo to fix your issue.

A lot of people prefer to do their production builds locally.

12reactions
jplhomercommented, Mar 21, 2017

Hi @aspitzer! My workaround for using a symlinked node_modules folder was to copy/paste the webpack.config.js from this repo to my project root (sibling to webpack.mix.js and package.json).

Then, I added a line to the copied file before Mix.initialize() which corrects the root path to the current directory (not the location of the symlinked modules):

// imports...

/**
 * Set the root path to where this current file is. Since we symlink
 * node_modules on production, Mix thinks we are in the shared folder instead
 * of the current build folder, which causes a failed build.
 */
Mix.Paths.setRootPath( path.resolve(__dirname) );

Mix.initialize();

Finally, I updated the production script inside package.json to "node node_modules/cross-env/bin/cross-env.js NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=webpack.config.js"

This is necessary because the constructor value for Mix.Paths.root() uses path.resolve() to find the current context. I don’t know NodeJS well enough to suggest an alternative approach, and the workaround above works fine for me 😃

cc https://github.com/JeffreyWay/laravel-mix/issues/386

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot find module webpack.mix · Issue #533 - GitHub
Mix needs to have a webpack.mix.js file in the project root, so if it can't find one, it makes sense that it will...
Read more >
"npm run prod" returns : Error Cannot find module webpack.mix
Hello, I try npm run prod but it's not working ! Error: Cannot find module '/data/www/(...).com/webpack.mix' at Function.Module.
Read more >
npm: Laravel-Mix directory missing - Stack Overflow
I'm trying to run npm run dev on a Laravel project, but I get the following error. Error: Cannot find module '/home/faramarz/todo/node_modules/ ...
Read more >
Cannot find module 'webpack-cli' error | bobbyhadz
To solve the "Cannot find module 'webpack-cli'" error, make sure to install webpack-cli globally by running the npm i -g webpack-cli command and...
Read more >
How to fix Error: cannot find module "webpack" - Educative.io
Solution · 1. Install webpack in the local app folder · 2. Link webpack to your project.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found