Laravel-mix: cross-env doesn't exist anymore? npm webpack scripts fail

Created on 27 Jun 2017  路  5Comments  路  Source: JeffreyWay/laravel-mix

I've had a problem for a while where npm run dev works on my local machine but in travis-ci it's blowing up. It did blow up on my machine in the past but I'd poked something and then it worked again. In the process of trying to figure out what was going on, I updated my local machine's version of laravel-mix and then it broke on this machine too.

I updated laravel-mix and nuked dependencies, the problem persisted.
Package.json:

{
  "private": true,
  "scripts": {
    "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",
    "watch": "node node_modules/cross-env/bin/cross-env.js NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
    "hot": "node node_modules/cross-env/bin/cross-env.js NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
    "production": "node node_modules/cross-env/bin/cross-env.js NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
  },
  "devDependencies": {
    "axios": "^0.15.3",
    "cross-env": "^5.0.1",
    "jquery": "^3.2.1",
    "laravel-mix": "^1.0.7",
    "lodash": "^4.17.4",
    "materialize-css": "^0.98.2",
    "vue": "^2.3.4"
  },
  "dependencies": {}
}

No clue what a .babelrc file is, so I assume I'm not using a custom one.

  • Laravel Mix Version: 1.0.7, but running the command npm list --depth=0 returns more errors than fit in my entire terminal history. Here's a snippet:
npm ERR! extraneous: is-utf8 /vagrant/node_modules/is-utf8
npm ERR! error in /vagrant/node_modules/is-utf8: Invalid version: "https://registry.npmjs.org/is-utf8/-/is-utf8-0.2.1.tgz"
npm ERR! extraneous: is-valid-glob /vagrant/node_modules/is-valid-glob
npm ERR! error in /vagrant/node_modules/is-valid-glob: Invalid version: "https://registry.npmjs.org/is-valid-glob/-/is-valid-glob-0.
3.0.tgz"
npm ERR! extraneous: is-zip /vagrant/node_modules/is-zip
npm ERR! error in /vagrant/node_modules/is-zip: Invalid version: "https://registry.npmjs.org/is-zip/-/is-zip-1.0.0.tgz"
npm ERR! extraneous: isarray /vagrant/node_modules/isarray
npm ERR! error in /vagrant/node_modules/isarray: Invalid version: "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz"
npm ERR! extraneous: isexe /vagrant/node_modules/isexe
  • Node Version (node -v): v7.5.0
  • NPM Version (npm -v): 5.0.4
  • OS: Vagrant (laravel/homestead (virtualbox, 2.1.0) guest on Windows 10 host. All commands executed in the vagrant box via ssh.

Description:

cross-env appears to not exist anymore once laravel-mix is updated, causing all npm scripts to fail.

vagrant@homestead:/vagrant$ npm run dev

> @ dev /vagrant
> 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

module.js:472
    throw err;
    ^

Error: Cannot find module '/vagrant/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:418:7)
    at startup (bootstrap_node.js:139:9)
    at bootstrap_node.js:533:3
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.
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!     /home/vagrant/.npm/_logs/2017-06-27T21_12_12_759Z-debug.log
vagrant@homestead:/vagrant$

Steps To Reproduce:

laravel new test
cd test
npm run dev

Most helpful comment

You have removed cross-env from your scripts but your scripts configuration is wrong.

"scripts": {
    "dev": "NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
    "watch": "NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
    "hot": "NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
    "production": "NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
  },

This should work for you. You got to remove the node and cross-env.

And if you are using npm v5, you got to delete package-lock.json before running npm install. There is a major issue with npm v5 where it deletes your packages when package-lock.json is present.

All 5 comments

Okay, so cross-env is no longer a mix dependency, but using laravel is supposed to have added it, but it doesn't? Is that therefore an issue I should be posting in laravel?

Or should I be removing cross-env from package.json?

Or manually adding the cross-env dependency?

Or some combination of those?

You have removed cross-env from your scripts but your scripts configuration is wrong.

"scripts": {
    "dev": "NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
    "watch": "NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
    "hot": "NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
    "production": "NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
  },

This should work for you. You got to remove the node and cross-env.

And if you are using npm v5, you got to delete package-lock.json before running npm install. There is a major issue with npm v5 where it deletes your packages when package-lock.json is present.

Okay, so that works... In vagrant but not in windows, which I suppose is the entire purpose of cross-env...

Thanks @ruchern that worked! =)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Micaso picture Micaso  路  3Comments

kpilard picture kpilard  路  3Comments

terion-name picture terion-name  路  3Comments

pixieaka picture pixieaka  路  3Comments

jpriceonline picture jpriceonline  路  3Comments