Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't Run > npm run dev #998

Closed
ghost opened this issue Jul 13, 2017 · 34 comments

Comments

@ghost
Copy link

commented Jul 13, 2017

(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.

@ThomHurks

This comment has been minimized.

Copy link

commented Jul 13, 2017

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

@ghost

This comment has been minimized.

Copy link
Author

commented Jul 14, 2017

@JeffreyWay

This comment has been minimized.

Copy link
Owner

commented Jul 14, 2017

@byanke-pcn Did you modify your webpack.mix.js file at all?

@ghost

This comment has been minimized.

Copy link
Author

commented Jul 14, 2017

Nope

@djzara

This comment has been minimized.

Copy link

commented Jul 15, 2017

I can confirm the exact same result

0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node',
1 verbose cli   '/usr/local/bin/npm',
1 verbose cli   'run',
1 verbose cli   'development' ]
2 info using npm@5.3.0
3 info using node@v7.10.1
4 verbose run-script [ 'predevelopment', 'development', 'postdevelopment' ]
5 info lifecycle @~predevelopment: @
6 info lifecycle @~development: @
7 verbose lifecycle @~development: unsafe-perm in lifecycle true
8 verbose lifecycle @~development: PATH: /usr/local/lib/node_modules/npm/bin/node-gyp-bin:/Users/zara/tcc/cafe/node_modules/.bin:/usr/local/lib/node_modules/npm/bin/node-gyp-bin:/Users/zara/tcc/cafe/node_modules/.bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/mysql/bin:/usr/local/sbin:/Users/zara/.composer/vendor/bin
9 verbose lifecycle @~development: CWD: /Users/zara/tcc/cafe
10 silly lifecycle @~development: Args: [ '-c',
10 silly lifecycle   'cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js' ]
11 silly lifecycle @~development: Returned: code: 1  signal: null
12 info lifecycle @~development: Failed to exec development script
13 verbose stack Error: @ development: `cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/lifecycle.js:289:16)
13 verbose stack     at emitTwo (events.js:106:13)
13 verbose stack     at EventEmitter.emit (events.js:194:7)
13 verbose stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/spawn.js:40:14)
13 verbose stack     at emitTwo (events.js:106:13)
13 verbose stack     at ChildProcess.emit (events.js:194:7)
13 verbose stack     at maybeClose (internal/child_process.js:899:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)
14 verbose pkgid @
15 verbose cwd /Users/zara/tcc/cafe
16 verbose Darwin 16.6.0
17 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "development"
18 verbose node v7.10.1
19 verbose npm  v5.3.0
20 error code ELIFECYCLE
21 error errno 1
22 error @ development: `cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js`
22 error Exit status 1
23 error Failed at the @ development script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]
@ghost

This comment has been minimized.

Copy link
Author

commented Jul 18, 2017

Similar error, upon trying different steps:

sudo apt install npm -y;
[cd to proj dir]
npm install cross-env@latest --save-dev
npm install webpack
npm install

Returns:

ubuntu@webdev:/var/www/laravel$ npm run watch

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

sh: 1: cross-env: Permission denied

npm ERR! Linux 4.4.0-83-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "run" "watch"
npm ERR! node v4.2.6
npm ERR! npm  v3.5.2
npm ERR! code ELIFECYCLE
npm ERR! @ 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`
npm ERR! Exit status 126
npm ERR! 
npm ERR! Failed at the @ watch script 'cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --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!     cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --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 a
@benyanke

This comment has been minimized.

Copy link

commented Jul 20, 2017

FYI, I consolidated my multiple github accounts, so my old account shows up as "ghost." I was the original author of this thread, and I'm still looking for assistance if you're willing.

@benyanke

This comment has been minimized.

Copy link

commented Jul 24, 2017

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

@bobby-drk

This comment has been minimized.

Copy link

commented Jul 24, 2017

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.

@benyanke

This comment has been minimized.

Copy link

commented Jul 24, 2017

What's the easiest way to get an old version of laravel mix? I'm relatively new to node/NPM

@ruchern

This comment has been minimized.

Copy link
Contributor

commented Jul 24, 2017

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

e.g. npm i laravel-mix@0.11.4

@patlecat

This comment has been minimized.

Copy link

commented Aug 2, 2017

I updated npm to v4.2, my nodejs is at v6.10, manually installed cross-env too and I updated EVERYTHING today, the box, homestead, Laravel, Virtualbox, Vagrant to the very latest! Still I get heaps of errors no matter what I try. See a sample error output here:

vagrant@homestead:~/Code/Laravel$ npm run dev --no-bin-link

> @ dev /home/vagrant/Code/Laravel
> 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:471
    throw err;
    ^

Error: Cannot find module '/home/vagrant/Code/Laravel/node_modules/cross-env/bin/cross-env.js'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.runMain (module.js:604:10)
    at run (bootstrap_node.js:390:7)
    at startup (bootstrap_node.js:150:9)
    at bootstrap_node.js:505:3

npm ERR! Linux 4.4.0-51-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "run" "dev" "--no-bin-link"
npm ERR! node v6.10.3
npm ERR! npm  v4.2.0
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 '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! Linux 4.4.0-51-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "run" "dev" "--no-bin-link"
npm ERR! node v6.10.3
npm ERR! npm  v4.2.0
npm ERR! path /home/vagrant/.npm/_logs/2017-08-02T20_59_26_511Z-debug.log.1507221106
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall open

npm ERR! Error: EACCES: permission denied, open '/home/vagrant/.npm/_logs/2017-08-02T20_59_26_511Z-debug.log.1507221106'
npm ERR!     at Error (native)
npm ERR!  { Error: EACCES: permission denied, open '/home/vagrant/.npm/_logs/2017-08-02T20_59_26_511Z-debug.log.1507221106'
npm ERR!     at Error (native)
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'open',
npm ERR!   path: '/home/vagrant/.npm/_logs/2017-08-02T20_59_26_511Z-debug.log.1507221106' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.

npm ERR! Please include the following file with any support request:
npm ERR!     /home/vagrant/.npm/_logs/2017-08-02T20_59_26_511Z-debug.log
@JeffreyWay

This comment has been minimized.

Copy link
Owner

commented Aug 2, 2017

Seems to me like you have an installation issue.

Error: Cannot find module '/home/vagrant/Code/Laravel/node_modules/cross-env/bin/cross-env.js'

It's telling you that it can't find cross-env, so it's not installed.

@patlecat

This comment has been minimized.

Copy link

commented Aug 3, 2017

@JeffreyWay Yes I can see that, but why does it say that after I installed it? Locally and globally (with -g)? I guess that the updating and refreshing of all the many components in a Homestead-Laravel installation have to be done in a specific order only and with the right versions to work well. Any deviation from it may break it all. Maybe you could have a look at that and what the preferred/minimal versions of everything should be for Laravel-Mix according to you! That would be very helpful if we had a recommendation from you for this.

I have to add, that I'm not a Linux expert and only just began using Laravel this year after watching your great intro videos.

@ruchern

This comment has been minimized.

Copy link
Contributor

commented Aug 3, 2017

@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

@patlecat

This comment has been minimized.

Copy link

commented Aug 3, 2017

@ruchern + @JeffreyWay Okay guys I got it fixed after many many oh so many weird steps and trials. Why is Laravel Mix not working correctly out of the box when installed on a Homestead with the latest Laravel? I don't get it. I had to search for tricks and workarounds already about 4 times this year only to fix the heaps of errors using it!

Anyhow, I updated my homestead Ubuntu and suddenly I had 6.11.2 but again npm 3.x. So I installed npm 4.2.0 manually. Then I copied over both the webpack.mix.js (adapting the paths, Laravel has no dist folder) content and the package.json too. Then an npm install and then an npm update and then...
finally the npm run dev and it ran finally!!! I'm sure the next time in a few months I will go through the same odyssey again because by then things will have changed again and documentation and installations will still be out of sync in different locations. Laravel Mix is like the entry point for every beginner and if things go bad there it ruins Laravel for them, not everyone is as obstinate as I am, as a long time developer I know that sometimes it takes days or weeks to fix a problem. But this should never have been a (recurring) problem for me at all.

it ran... https://open.spotify.com/track/6kwV6Bl9P76cL8O93bcWaW

@JeffreyWay

This comment has been minimized.

Copy link
Owner

commented Aug 3, 2017

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.

@JeffreyWay JeffreyWay closed this Aug 3, 2017

@patlecat

This comment has been minimized.

Copy link

commented Aug 3, 2017

@JeffreyWay If this feels weird to you then imagine how much it does to me :D Anyhow, I copied as @ruchern suggested the content of those files from the installation instruction in this repo assuming that it's the latest working code and it was. But no npm install or update beforehand did give me the new working code.
Your examples show a dist folder which does not exist in Laravel as far as I know.

@devcircus

This comment has been minimized.

Copy link
Contributor

commented Aug 3, 2017

I started a fresh project today with the latest laravel and mix, using homestead and can confirm everything worked perfectly out-of-the-box.

Npm and node are strange beasts that can sometimes behave oddly. Once you figure it out, do it again and again until you know each step thoroughly.

@ruchern

This comment has been minimized.

Copy link
Contributor

commented Aug 4, 2017

@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
@patlecat

This comment has been minimized.

Copy link

commented Aug 4, 2017

@ruchern I didn't say that it can't run perfectly well, but it obviously did not with me. And that is not so uncommon in software development that things run fine with some users while it breaks with others. It's annoying but part of the job to find out why it breaks. I can't say what I do differently or maybe even wrong each time, but I noticed that I'm by far not the only one encountering such problems. But thanks a lot for your help.
Oh and I definitely need to use "--no-bin-link" from time to time, else some commands fail by saying "symlink"!

Update: I got things to work fine at home but my homestead-laravel install at the office is still broken and applying the same steps won't fix it here sigh

@benyanke

This comment has been minimized.

Copy link

commented Aug 10, 2017

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).

@rvrbk

This comment has been minimized.

Copy link

commented Sep 7, 2017

@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?

@Grebenschikov

This comment has been minimized.

Copy link

commented Sep 7, 2017

@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

@ruchern

This comment has been minimized.

Copy link
Contributor

commented Sep 7, 2017

@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>
@benyanke

This comment has been minimized.

Copy link

commented Sep 7, 2017

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

@simonecosci

This comment has been minimized.

Copy link

commented May 3, 2018

npm rebuild should solve

@djzara

This comment has been minimized.

Copy link

commented May 3, 2018

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?

@jiezhang917

This comment has been minimized.

Copy link

commented Jun 26, 2018

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 **

@cotiga

This comment has been minimized.

Copy link

commented Jul 24, 2018

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

@AndyLeeRobinson

This comment has been minimized.

Copy link

commented Sep 3, 2018

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

@ROG3RB0T

This comment has been minimized.

Copy link

commented Sep 25, 2018

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

This works for me.

@choyan

This comment has been minimized.

Copy link

commented Nov 17, 2018

npm rebuild fixes my problem.

@Protected

This comment has been minimized.

Copy link

commented Jul 10, 2019

If you made it here after having this issue on a Windows host: Do not run npm inside a shared host folder. Just don't. It will run fine in a directory that exists only in Homestead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
You can’t perform that action at this time.