laravel-mix: Can't Run > npm run dev

(Ran testing steps, issue still occurred)

  • Laravel Mix Version: (Returns (empty))
  • Node Version v8.1.4
  • NPM Version 5.0.3
  • OS: Ubuntu 16.04.2 LTS in vagrant (host OS: same)

Description:

I’ve tried all the various solutions I have found online (including in other issue tickets here) and I’m still unable to get this to work in my Laravel installation.

I’m running in Vagrant, so I can easily destroy and rebuild my VM quickly, so nothing is off the table when it comes to debugging.

Steps To Reproduce:

  1. Installed NodeJS using the following command (as per the NodeJS site)
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -;
sudo apt-get install -y nodejs;
  1. cd /var/www/laravel
  2. npm install
  3. npm run dev returns the following output:
ubuntu@webdev:/var/www/laravel$ npm run dev

> @ dev /var/www/laravel
> npm run development


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

sh: 1: cross-env: not found
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
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! spawn ENOENT
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 WARN Local package.json exists, but node_modules missing, did you mean to install?

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/ubuntu/.npm/_logs/2017-07-13T21_39_35_953Z-debug.log
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 WARN Local package.json exists, but node_modules missing, did you mean to install?

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/ubuntu/.npm/_logs/2017-07-13T21_39_35_970Z-debug.log
ubuntu@webdev:/var/www/laravel$ 

Also, the contents of /home/ubuntu/.npm/_logs/2017-07-13T21_39_35_970Z-debug.log are:

0 info it worked if it ends with ok
1 verbose cli [ '/usr/bin/nodejs', '/usr/bin/npm', 'run', 'dev' ]
2 info using npm@5.0.3
3 info using node@v8.1.4
4 verbose run-script [ 'predev', 'dev', 'postdev' ]
5 info lifecycle @~predev: @
6 silly lifecycle @~predev: no script for predev, continuing
7 info lifecycle @~dev: @
8 verbose lifecycle @~dev: unsafe-perm in lifecycle true
9 verbose lifecycle @~dev: PATH: /usr/lib/node_modules/npm/bin/node-gyp-bin:/var/www/laravel/node_modules/.bin:/home/ubuntu/bin:/home/ubuntu/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/ubuntu/.composer/vendor/bin:/home/ubuntu/.config/composer/vendor/bin:/var/www/laravel
10 verbose lifecycle @~dev: CWD: /var/www/laravel
11 silly lifecycle @~dev: Args: [ '-c', 'npm run development' ]
12 silly lifecycle @~dev: Returned: code: 1  signal: null
13 info lifecycle @~dev: Failed to exec dev script
14 verbose stack Error: @ dev: `npm run development`
14 verbose stack Exit status 1
14 verbose stack     at EventEmitter.<anonymous> (/usr/lib/node_modules/npm/lib/utils/lifecycle.js:283:16)
14 verbose stack     at emitTwo (events.js:125:13)
14 verbose stack     at EventEmitter.emit (events.js:213:7)
14 verbose stack     at ChildProcess.<anonymous> (/usr/lib/node_modules/npm/lib/utils/spawn.js:40:14)
14 verbose stack     at emitTwo (events.js:125:13)
14 verbose stack     at ChildProcess.emit (events.js:213:7)
14 verbose stack     at maybeClose (internal/child_process.js:897:16)
14 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:208:5)
15 verbose pkgid @
16 verbose cwd /var/www/laravel
17 verbose Linux 4.4.0-83-generic
18 verbose argv "/usr/bin/nodejs" "/usr/bin/npm" "run" "dev"
19 verbose node v8.1.4
20 verbose npm  v5.0.3
21 error code ELIFECYCLE
22 error errno 1
23 error @ dev: `npm run development`
23 error Exit status 1
24 error Failed at the @ dev script.
24 error This is probably not a problem with npm. There is likely additional logging output above.
25 verbose exit [ 1, true ]

Assistance would be appreciated.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 6
  • Comments: 34 (5 by maintainers)

Most upvoted comments

npm rebuild should solve

Anyone? Surely I can’t be the only one running laravel mix on an Ubuntu Server…

npm rebuild fixes my problem.

In my case, I accomplished the permission fixing in my Vagrant mount by adding the following to my Vagrantfile:

      config.vm.synced_folder "www/laravel/node_modules", "/var/www/laravel/node_modules", id: "wwwroot_node-executable",
          create: true,
          owner: "ubuntu",
          group: "www-data",
          mount_options: ["dmode=775,fmode=775"]

Just returned to this after focusing on some other projects for a while.

In my case, it turned out to be as simple as my JS files weren’t being set as executable in the filesystem (and due to my use of vagrant, that could not be modified through a simple chmod).

Did you install cross-env? npm install cross-env@latest --save-dev

@rvrbk small research showed this solution: run

chmod -R 765

inside laravel project directory

It’s not right way to fix, but it work’s

cd /path/of/project
chmod -R a+x node_modules

For my case, it was because corss-env was installed by another user, and permission is limited to mine. So what i did is sudo rm -rf node_modules, then npm install, then npm run **

@Grebenschikov That is a bad way to set executable permissions.

chmod a+x modifies the argument’s mode while chmod 755 sets it. Try both variants on something that has full or no permissions and you will notice the difference.

https://stackoverflow.com/a/18596834/4031163

For missing executable permissions, use:

chmod -R a+x <directory>

Just my additional two cents, but given the issues here I find it worthwhile to mention these sorts of gotchas and caveats in the documentation. Would anyone else find that useful?

Why is Laravel Mix not working correctly out of the box when installed on a Homestead with the latest Laravel?

It does work out of the box. I’m not sure what issue you ran into. Few things seem weird to me, like:

Then I copied over both the webpack.mix.js (adapting the paths, Laravel has no dist folder)

I don’t know what you mean by this. Laravel’s mix file makes no reference at all to a dist/ folder. And you don’t need to copy any package.json file over.

@benyanke npm i laravel-mix@major.minor.patch

e.g. npm i laravel-mix@0.11.4

cd /path/of/project/node_modules find ./ -type f -name ‘*.js’ -exec chmod 775 {} \;

@patlecat Your dev script looks wrong.

Use this:

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

If you want to, add cross-env before NODE_ENV=...

And try not to use --no-bin-link

https://github.com/JeffreyWay/laravel-mix/blob/master/docs/installation.md#npm-scripts

@benyanke I’ve run into the same issue and want to apply the solution you gave in the last comment. Can you tell me on which files you changes the permissions?

@patlecat Laravel-Mix works perfectly out of the box and it worked for all of my projects so far. So I have no idea what have you done wrong.

I do not use Homestead but Valet instead.

I am running

  • npm 5.3.0/yarn 0.27.5 (Currently yarn till npm fixes their issue with package-lock.json)
  • node 8

I’m having the same problem, but I didn’t have anything to add to the conversation. We made too many changes to understand what was different. We rolled back to older versions of everything, and decided to wait. Sorry to be unhelpful.