Stretsh's avatar

cross-env not found on npm run dev

I can't seem to make Laravel Mix work out of the box. When I run npm run dev, I get the cross-env not found error.

My environment, all freshly installed:

  • Windows 10 64bit
  • VirtualBox 5.1.14
  • Vagrant 1.9.2
  • Homestead 2.0.0
  • Laravel 5.4.16

Installed VirtualBox, then Vagrant. Ran vagrant box add laravel/homestead, ran git clone https://github.com/laravel/homestead.git homestead in my D:\Werk directory. cd'd into homestead, did git checkout v5.1.0, as per Laravel Docs, edited Homestead.yaml, as seen below, and booted up the VM with vagrant up.

---
box: laravel/homestead
ip: "192.168.111.10"
memory: 2048
cpus: 1
provider: virtualbox

authorize: C:\Users\xxxxxx\.ssh\id_rsa.pub

keys:
    - C:\Users\xxxxxx\.ssh\id_rsa

folders:
    - map: D:\Werk\projects
      to: /home/vagrant/projects

sites:
    - map: homestead.app
      to: /home/vagrant/projects/homestead
    - map: visitors.app
      to: /home/vagrant/projects/visitors/public

databases:
    - homestead
    - visitors

SSH'd into box (127.0.0.1:2222), ran sudo apt-get upgrade for the latest server software, cd'd to /home/vagrant/projects in which I ran laravel new visitors. Once finished, I then cd'd into the visitors directory, where I ran npm install --no-bin-links. I get a Maximum call stack size exceeded error, and in accordance with GitHub issue answers, I ran the command again, this time successfully.

  • Node: 6.10.0 (also tried with v7.7.3)
  • npm: 3.10.10 (also tried with v4.1.2)

Now when I run npm run dev I get a sh: 1: cross-env: not found error. In accordance with what @JeffreyWay said here, I installed cross-env with npm: npm install cross-env -D --no-bin-links, to no avail.

I tried several "solutions" out there. from adding "bin": { "cross-env": "dist/bin/cross-env.js"}, to the package.json to babel related stuff in the same file. Nothing seems to work. When I replace cross-env with node node_modules/cross-env/dist/bin/cross-env.js in the package.json file, I get:

 error  in ./resources/assets/sass/app.scss

Module build failed: ModuleBuildError: Module build failed: Error: ENOENT: no such file or directory, scandir '/home/vagrant/projects/visitors/node_modules/node-sass/vendor'

When I make that directory (found a post somewhere that suggests that the vendor folder is not created during installation of node-sass), then i get the next error:

 error  in ./resources/assets/sass/app.scss

Module build failed: ModuleBuildError: Module build failed: Error: Missing binding /home/vagrant/projects/visitors/node_modules/node-sass/vendor/linux-x64-48/binding.node
Node Sass could not find a binding for your current environment: Linux 64-bit with Node.js 6.x

Found bindings for the following environments:


This usually happens because your environment has changed since running `npm install`.
Run `npm rebuild node-sass --force` to build the binding for your current environment.

So I run `npm rebuild node-sass --force --no-bin-links', which downloads and compiles node-sass from source, it seems.

Then, and only then, does it work. But I don't believe that this developers are expected to run these steps every time they bring their vagrant machine up. So either I am missing something crucial or there is a bug. Any advice?

0 likes
17 replies
WebKenth's avatar

Are you required to use a virtual machine?

Since you are using windows I would recommend using Laragon unless you are otherwise required to use a virtual machine.

You avoid all the hassle of setting up machines

Stretsh's avatar

I have read about "the ease of using Homestead" so often, and I heard it in a lot of Jeff's video's, that i wanted to try it out. So it's not required, but i'd like to try it out.

Plus, I don't mind being a tester, to help find issues, so me installing it is me helping out.

I will take a look at Laragon later. Thanks

bashy's avatar

What does your package.json look like?

1 like
Stretsh's avatar

Original:

{
  "private": true,
  "scripts": {
    "dev": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
    "watch": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
    "watch-poll": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --watch-poll --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
    "hot": "cross-env 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": "cross-env 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",
    "bootstrap-sass": "^3.3.7",
    "cross-env": "^3.2.4",
    "jquery": "^3.1.1",
    "laravel-mix": "^0.8.3",
    "lodash": "^4.17.4",
    "vue": "^2.1.10"
  }
}

Edited:

{
  "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/dist/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",
    "watch-poll": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --watch-poll --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
    "hot": "node node_modules/cross-env/dist/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/dist/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",
    "bootstrap-sass": "^3.3.7",
    "cross-env": "^3.2.4",
    "jquery": "^3.1.1",
    "laravel-mix": "^0.8.3",
    "lodash": "^4.17.4",
    "vue": "^2.1.10"
  }
}
4 likes
Rav23's avatar

You need to check if that path exists in your node_modules folder (path of the cross-env library). At times it's located within the dist folder, other times it's located outside it.

Gerard's avatar

Thanks @Stretsh! I finally got it to work changing my package.json scripts to yours.

1 like
dmhamilt's avatar

Stretsh your solution fixed my npm run dev problem but for watch it runs but doesn't sense file changes. Any ideas?

Stretsh's avatar

I think it could be linked to the same reason why the full path should be used instead of just cross-env. Maybe a permission problem? I still have no clue...

I haven't tried it since posting this, so I have no idea if it was fixed or not. I wonder if i should report a bug...

sl0wik's avatar

Try npm install cross-env -g.

6 likes
Vaggelis2018's avatar

After npm update try npm install --save. I tried too many solutions and only saving them worked!

2 likes
dmhamilt's avatar

I have tried lots of solutions and finally got windows 10 to create symbolic links, which is the root of most of window users issues heartache.

First turn on Windows 10 Developer. http://www.wikihow.com/Enable-Developer-Mode-in-Windows-10 Search for Developer Features in Settings change it to Developer Mode.

Secondly make sure you have permission to make symbolic links. https://superuser.com/questions/104845/permission-to-make-symbolic-links-in-windows-7 Search for local security policy and click through local security policy \ local polices \ user right assignment\ create symbolic link Give yourself permission. Note: put your user name in all lowercase and check names. Oddly this worked for me. But spelling it with mixed case did not.

Lastly When you open git bash, run it as administrator. Now this is a point of frustration because I often forget. So make it default to open as admin. Make a shortcut on the desktop for git bash. right click on the shortcut \ properties\ advance and check run as administrator.

Reboot the machine and you should be much better off.

If somebody know how to paste screen shots please let me know. I cant get them in here.

akoper's avatar

I am doing Laracast's "laravel-from-scratch-2017/episodes/14" and "npm run development" is dying with fatal errors on me, too. Win10/Vagrant/Homestead/Laravel 5.6 environment. Error:

cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js

events.js:183\n throw er; // Unhandled 'error' event\n ^\n

Error: spawn node_modules/webpack/bin/webpack.js ENOENT\n at _errnoException (util.js:1022:11) at Process.ChildProcess._handle.onexit (internal/child_process.js:190:19) at onErrorNT (internal/child_process.js:372:16) at _combinedTickCallback (internal/process/next_tick.js:138:11) at process._tickCallback (internal/process/next_tick.js:180:9) at Function.Module.runMain (module.js:686:11) at startup (bootstrap_node.js:187:16) at bootstrap_node.js:608:3 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! /home/vagrant/.npm/logs/2018-04-09T1801_23_306Z-debug.log

plenty's avatar

A HUGE part of getting past my cross-env grief involved running the following command:

npm rebuild
4 likes
Jaikangam's avatar

Me installing normal without laragon or Virtual host. after the hours of research i found the solution. here is how i did

  1. npm install cross-env -g
  2. npm install --save

after that npm run dev or npm run build Boom! Laravel Mix Build Successful it is working.....

3 likes
abdulqadeerkamboh's avatar

when i run yarn watch then this error massage shows:

dev npm run development

development cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js

[webpack-cli] Error: Unknown option '--hide-modules' [webpack-cli] Run 'webpack --help' to see available commands and options

Please or to participate in this conversation.