laravel-mix: Cannot find module webpack.mix
- 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
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 22 (1 by maintainers)
Commits related to this issue
- fix using a symlinked node_modules folder , don't compile assets. refer: https://github.com/JeffreyWay/laravel-mix/issues/533#issuecomment-287960097 — committed to jiemoon/Jblog by jiemoon 7 years ago
- Updated the rootPath to the working directory of the node process. (#1719) Currently laravel-mix breaks when your `node_modules` directory is a symlink. This is due to the fact that relatives paths d... — committed to laravel-mix/laravel-mix by stephan-v 6 years ago
- Updated the rootPath to the working directory of the node process. (#1719) Currently laravel-mix breaks when your `node_modules` directory is a symlink. This is due to the fact that relatives paths d... — committed to devstar0826/laravel-mix by stephan-v 6 years ago
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.
Webpack-mix is a huge shitstorm and I’d recommend not to use it, indeed fuck you Jeffrey ^^
Hi @aspitzer! My workaround for using a symlinked
node_modulesfolder was to copy/paste thewebpack.config.jsfrom this repo to my project root (sibling towebpack.mix.jsandpackage.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):Finally, I updated the
productionscript insidepackage.jsonto"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()usespath.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
I know this is old but running
npm install laravel-mixfixed my issue.This fix does not work on newest version? Anyone has fix?
@JeffreyWay - this may not be the best place to ask this, but your comment that a lot of people prefer to do their builds locally … I would love to do my builds locally, but there are a few reasons why I feel it doesn’t work:
I’d love to know what the best practices for this are, because these sure don’t seem like good practices at all.
@JeffreyWay I’m pretty sure is a problem with envoyer and symbolic links. Folder where project is deployed is on the current. And node_modules is a symbolic link. I think problem is when on the node_modules tryes to go up a directory and that directory is not laravel root. (because node_modules is a symbolic link to avoid download everything on every deploy)
So is looking in this directory: /home/forge/XXX/storage/app/webpack.mix
When it should be looking here: /home/forge/XXX/current/webpack.mix
surprised it wasn’t solved. Was running into the same issue.
And a lot of people don’t, simply because production server has more ram/cores/better hdd and other reasons. Both ways is ok.
Hi @JeffreyWay. Why not check for an environment variable to define the root path? If the variable is not defined, fallback to the automatic root path detection.
I don’t see why webpack is perfectly fine being able to resolve to a webpack configuration file from a symlinked node_modules directory but this can not be properly solved for laravel-mix. I have been struggling for this for an hour now because of the confusing import fest within laravel-mix.
Laravel-mix is simplying trying to resolve something relatively while Webpack is doing something entirely different to fetch the default webpack config.
I hope I can respond with some more information if I figure this out.
@cerw Thanks for your idea. But all in all, I decided to realize the idea of @jplhomer
copy webpack.config.js in a root directory and modify composer.json for it. Start of the webpack.config.js file:
Anyway, I hope that Jeffrey will fix it in the next releazes.
And there is definitely a
storage/app/webpack.mix.jsfile?