Polecalex's avatar

Laravel Mix npm run errors.

Hello guys, I am pretty new to laravel, I'm still learning my way around and everything however I decided I would have a go at the laravel mix compiler for assets so that I can start to use processors on projects. I went through the install procedure, installing nodejs, using npm install --no-bin-links and all of that went perfectly! However when I try to use any of the "npm run" commands such as dev, production or watch, it just shoots out an error.

Node: v8.1.0 NPM: v5.0.3 OS: Windows 10.

C:\Users\Duck\Documents\Laravel\test>npm run dev

> @ dev C:\Users\Duck\Documents\Laravel\test
> npm run development


> @ development C:\Users\Duck\Documents\Laravel\test
> cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js

'cross-env' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @ development: `cross-env 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 @ development 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\Duck\AppData\Roaming\npm-cache\_logs\[2017-06-12T14_58_02_484Z-debug.log](https://pastebin.com/KkMup8VS)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @ dev: `npm run development`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the @ dev 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\Duck\AppData\Roaming\npm-cache\_logs\[2017-06-12T14_58_02_521Z-debug.log](https://pastebin.com/UyE5CTuQ)

Links to logs are located within the text.

0 likes
3 replies
Cronix's avatar

You didn't mention which version of laravel-mix you are using, but the most recent (1.x.beta) removed the 'cross-env' package, which you might actually need for windows, but they left the reference to it in the scripts section.

2 options:

  1. install cross-env by adding "cross-env":"^5.0.1" to your package.json file and then running npm install

2nd option is to edit package.json and remove the references to 'cross-env' from the commands defined in the scripts section (dev/watch/production/etc). This may/may not work bc of windows, but I'd try this first. If that doesn't work, add the cross-env commands back in and install the cross-env package.

1 like
Polecalex's avatar
Polecalex
OP
Best Answer
Level 1

Sorry about that, I wasn't sure how to find the version of mix.

I was actually able to find out why it hasn't been working. In the documentation for mix, it says to run npm install and then straight to npm run dev / production but however, after a while of reading around, i found out about npm rebuild. So i installed a new copy of laravel and ran install, rebuild and then run and it works! I'm not sure why it wasn't working, maybe it couldn't find the cross-env as it wasn't built properly or something? Not sure, but yeah, that's how I fixed it, thank you for your support anyway!

Stratos's avatar

I've also had a problem with a fresh NodeJS 8.0 install where it wasn't installing ALL of the dependencies, this made npm run to fail. I had to run https://www.npmjs.com/package/npm-install-missing so it would force to download all of the dependencies. After doing this, npm worked as usual.

Please or to participate in this conversation.