laravel-mix: Cannot find module cross-env
- Laravel Mix Version: 0.8.7
- Node Version (
node -v): 7.6.0 - NPM Version (
npm -v): 4.3.0 - OS: MacOS
Description:
I am using Spark (latest version) but when I compiled css and js by using npm run dev then I got an error:
Cannot find module '/PATH/node_modules/cross-env/bin/cross-env.js'
at Function.Module._resolveFilename (module.js:470:15)
at Function.Module._load (module.js:418:25)
at Module.runMain (module.js:605:10)
at run (bootstrap_node.js:422:7)
at startup (bootstrap_node.js:143:9)
at bootstrap_node.js:537:3
npm ERR! Linux 3.19.0-25-generic
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "dev"
npm ERR! node v7.6.0
npm ERR! npm v4.3.0
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @ dev: `node node_modules/cross-env/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 @ dev script 'node node_modules/cross-env/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 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/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
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /home/vagrant/.npm/_logs/2017-02-26T08_26_31_924Z-debug.log
I tried to update npm, node, laravel-mix and remove all modules in node_modules and re-install but I still got that error.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 26
- Comments: 70 (13 by maintainers)
Commits related to this issue
- fix npm build error https://github.com/JeffreyWay/laravel-mix/issues/478 — committed to nus-mtp/bill-organizer by dev-seahouse 7 years ago
- Cross-env new paths Please see this thread: https://github.com/JeffreyWay/laravel-mix/issues/478 — committed to vinkla/wordplate by puredazzle 7 years ago
- Add cross-env as a dependency and update paths — committed to laravel/laravel by driesvints 7 years ago
- Update package.json - see https://github.com/JeffreyWay/laravel-mix/issues/478 — committed to rosswintle/today-i by rosswintle 7 years ago
cross-env must have updated its paths, it has “cross-env/dist/bin” not “cross-env/bin/”
in package.json (EDIT)
@phuclh
package.jsonpaste thisnpm install --save-dev cross-envnpm installNow npm run dev npm run watch
Actually, I fixed with this sequence. After that, I’m able to run
npm run devinsidevagranth sshconnectionI do not alter
package.jsonfileOPTIONAL: If you want to really clear your vagrant box do this BEFORE starting
Then go on removing local
node_modulesfolder from your code folderIf you’re using homestead, you get this error if you run the command in the VM.
https://github.com/JeffreyWay/laravel-mix/issues/447
Try the scripts in the link rather than the ones you are currently using in your config
In package.json, npm run dev is directly trying to run ‘cross-env + command’
If you install cross-env globally, it will fix the problem.
sudo npm i -g cross-envIt is that simple.
For the latest
"laravel-mix": "^5.0.0",I had to change fromdisttosrccause there is no dist incross-env. So my scripts are:You’ll need to change the references to this path for all scripts, including:
Replacing “cross-env/bin/” with “cross-env/dist/bin” in package.json solved my issue…
Now its working fine. Thanks @dwoodard
@JeffreyWay can you please update package.json with laravel default installation?
We removed the dependency with the 1.0 release. It was the right time to remove that dependency. It takes five seconds to do
npm i cross-env.here is a complete solution: http://rapidsol.blogspot.com/2018/04/laravel-5-cross-env-is-not-recognized.html
Thank you. Had split some hairs because of this.
@realtebo It’s not required. I don’t think people understand that the only use for cross-env is to allow for cross-platform npm scripts. If you’re a Mac user, you don’t need it. If you’re a Windows users, either pull it in, or tweak the npm script to fit your platform. Mix, itself, does not depend upon cross-env.
We had the same issue here but changing the package.json file is not a good option when you work in a big team with different dev environments. My solution here is a simple
npm install -g cross-env. That should do the trick.Thanks for the detailed information @mostafa6765!
Thanks @dwoodard 😄
Can you check your installed version of Mix again? 0.8.7 doesn’t exist.
Thanks, I solved my problem by following your advice. This works. Just for sharing, after that I am still facing another error: “Cannot read property ‘js’ of undefined” then I have to do the following steps then after that only it is fixed:
Simply remove the braces surrounding the mix on your first line: const mix = require(‘laravel-mix’);
Reference: https://stackoverflow.com/questions/56891915/laravel-typeerror-cannot-read-property-js-of-undefined
I just install yarn command globally: https://yarnpkg.com/en/docs/install
This help me a lot to clear my panoram…
I use windows without cross-env. I simply adjusted my script in package.json as below:
@JeffreyWay it takes a short time to install, but much more time to investigate why a script that comes with the framework ends in error.
The way to describe that a Node application needs additional code to run is by including it in
package.json, why not use that mechanism?(Added to my list of Laravel tips & pitfalls)
@JeffreyWay I have no problem following installation instructions, if all that is documented there. Things change, I accept and welcome that, but I’m no psychic I can’t guess what changed.
@ruchern Okay so you recommend compiling the website in the VM (on linux) right? I would be totally confused if that was not the intention after all. And you recommend staying on nodejs 6.11.x but updating only npm and to the latest version 4.x?
For those who are forced to bounce-around between environments (e.g., developing on Windows with Vagrant and a mounted filesystem but deploying to GNU/Linux), this issue can arise if you
npm install --no-bin-links, which is sometimes necessary to resolve symbolic linking issues on Windows when using a mounted filesystem within a development VM.Using the
--no-bin-linksswitch effectively causes thecross-envbinary location to change from just justcross-env(node_modules/.bin/cross-env, technically) tonode_modules/cross-env/dist/bin/cross-env.js, in which case it is necessary to specify the full path, explicitly, inpackage.json, as described in a previous comment.Mix has a full test suite. Just fork, clone, and run the tests on the OS of your choosing.
Is Laravel-Mix actually known to work consistently and flawlessly on any other platform than Mac OSX? I wonder, do you guys even test it as thoroughly under Linux like Ubuntu and Homestead?
In addition to @JeffreyWay, Linux also does not need
cross-env.@JeffreyWay
Why? If it IS NEEDED it IS a dependency…
I’m sure I’ve lost something …
I’ve done some research in the last few days and it does seem that thoughts on this have changed in recent years. When I first started with homestead years ago, there were so many issues with npm on vagrant that everyone recommended running it on the host. I’ve stuck with that and never had any problems. I even use yarn on the host machine(windows). However it seems I’m behind on the current trend and although it may be a little slower, npm and yarn should work just fine on the vm.
@patlecat Yes, you should be and I assume you did, run the scripts in the Homestead environment.
As for the npm version, the latest now is v5.3.0, but it is plagued with a lot of problems. v4 is very stable so to speak. I am not sure if v4 is outdated that it won’t work anymore.
@ruchern thanks for the info.
For me this means an application that previously build successfully suddenly failed. I hope this will be fixed, manually adding the package isn’t a great solution.
It’s July 2017, I did a fresh installation of Homestead (on Windows 10) and Laravel 5.4 and still got this cross-env error during npm install !! But now the mix file looks different with the paths so the above tips won’t work anymore. Even after installing the cross-env pckg manually to -g I get errors with every “npm install…” or “npm run dev” command i execute inside of Homestead!
Also “npm run dev” produces the “cross-env not found” error (plus many more following that)!
Why is this still a problem after such a long time at this very basic and important functionality?
Tell the author that this fails on your system: npm ERR! cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js