laravel-mix: Cannot find module '/home/vagrant/Code/blog/node_modules/cross-env/bin/cross-env.js

  • Laravel Mix Version: 0.6.0
  • Node Version (node -v): 5.10.1
  • NPM Version (npm -v): 3.8.3
  • OS: macOS Sierra 10.12.3

Description:

On my fresh Laravel 5.4.14, running npm run dev gets into this error:

> 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:341
    throw err;
    ^

Error: Cannot find module '/home/vagrant/Code/blog/node_modules/cross-env/bin/cross-env.js'
    at Function.Module._resolveFilename (module.js:339:15)
    at Function.Module._load (module.js:290:25)
    at Function.Module.runMain (module.js:447:10)
    at startup (node.js:146:18)
    at node.js:404:3

npm ERR! Linux 3.19.0-25-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "run" "dev"
npm ERR! node v5.10.1
npm ERR! npm  v3.8.3
npm ERR! code ELIFECYCLE
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/Code/repoducing-laravel-mix-issue-519/npm-debug.log

So I read through these similar issues, https://github.com/JeffreyWay/laravel-mix/issues/519, https://github.com/JeffreyWay/laravel-mix/issues/523, https://github.com/laravel/framework/issues/17528, but got no luck.

After updating my Laravel from 5.4.14 to 5.4.15 by running composer install and npm install afterwards, still got the same error.

Also reproduced on a fresh Laravel 5.4.15 installation by running composer global require "laravel/installer", the error still persist in npm run dev.

Steps To Reproduce:

  1. Install a new Laravel app: $ composer create-project --prefer-dist laravel/laravel blog
  2. Install NPM modules: $ npm install
  3. Run: $ npm run dev

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 1
  • Comments: 16

Most upvoted comments

The cross-env package change the bin directory path from cross-env/bin to cross-env/dist/bin

just update your package.json file:

...
scripts: {
    "dev": "node node_modules/cross-env/dist/bin/cross-env.js...

sudo npm install sudo npm run dev

Here’s my package.json:

{
  "private": true,
  "scripts": {
    "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",
    "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": {
    "bootstrap-sass": "^3.3.7",
    "jquery": "^3.1.0",
    "laravel-mix": "^0.6.0",
    "lodash": "^4.16.2",
    "vue": "^2.0.1"
  }
}

The only thing changed here is that I’ve changed:

"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",

to:

"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",

Still having the errors thou up to now.

@doncadavona Update Node. You have an outdated version.

@asimshazad @shemi already posted a solution for your issue.