laravel-mix: npm run dev Error on fresh Laravel installation

Laravel version: 5.4.15 NodeJS version: 7.7.1 npm version: 4.1.2

Laravel/Homestead on Ubuntu 16.04

webpack.mix.js is default:

const { mix } = require('laravel-mix');

mix.js('resources/assets/js/app.js', 'public/js')
   .sass('resources/assets/sass/app.scss', 'public/css');

Error

vagrant@homestead:~/www/new$ npm run dev

> @ dev /home/vagrant/www/new
> 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 '/home/vagrant/www/new/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:425:7)
    at startup (bootstrap_node.js:146:9)
    at bootstrap_node.js:540:3

npm ERR! Linux 3.19.0-25-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "run" "dev"
npm ERR! node v7.7.1
npm ERR! npm  v4.1.2
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/www/new/npm-debug.log

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 4
  • Comments: 49 (1 by maintainers)

Most upvoted comments

@ibtissambth Please try my steps.

Step1: composer update Step2: rm -rf node_modules Step3: npm cache clean Step4: npm install Step5: npm outdated In this step, I update my laravel-mix version to 1.2.0, it is in the package.json. Step6: npm install Step7: npm run dev After all these steps, everything is good.

Hí, Ramseyjiang.

Step 1- Do fresh LARAVEL project download. Step 2- Replace package.json content , with the content from the link provided above. Step 3- Through command prompt - npm install --no-bin-links Step 4- Through command prompt - npm rebuild

It worked for me.

Replace Package.Json Content with the content from https://github.com/laravel/laravel/blob/master/package.json

and then do npm install again.

@nitin19srivastava I fixed it that issue by myself way.

Step1: composer update Step2: rm -rf node_modules Step3: npm cache clean Step4: npm install Step5: npm outdated In this step, I update my laravel-mix version to 1.2.0, it is in the package.json. Step6: npm install Step7: npm run dev After all these steps, everything is good.

I followed @jhunexjun solution… well am not very sure if his solution really did the magic but I also Replaced Package.Json Content with the content from https://github.com/laravel/laravel/blob/master/package.json

and then did npm install again. I was still having some errors but this time it was a different one which npm failed to download somethings form github. Looking at the error I find out that it was because I was behind a proxy though I had the proxy configurations successfully set for npm but it still didn’t work so I had to get another access to the internet without a proxy and this time it worked.

@dikiaap I find there solution. In node_module/laravel-mix/package.json should add this:

"bin": {
    "cross-env": "dist/bin/cross-env.js"
},

After updating PACKAGE.JSON., you can do NPM REBUILD. IT WORKS FOR ME.

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! C:\Users\user\AppData\Roaming\npm-cache_logs\2021-01-31T00_39_15_501Z-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 ERR! A complete log of this run can be found in: npm ERR! C:\Users\user\AppData\Roaming\npm-cache_logs\2021-01-31T00_39_15_555Z-debug.log

rebuild your npm

npm rebuild

Do the fresh LARAVEL installation, replace PACKAGE.JSON content with the link mentioned in above comment. Install NPM and then run NPM REBUILD.

If still not working, tell me your email or Dropbox I’d , so that I can do the same and forward​ it to you.

For what it’s worth, it was a lack of RAM on our server. Same exact general error. Adding some swap solved it. But it was hard to spot as the log didn’t say anything and you usually have 1 terminal open that’s locked out of other commands like “free -m” while it’s compiling.

This worked for me npm install --global cross-env

I struggled a lot with this issue but when I used Yarn everything is resolved:

yarn install

Hi all,

I’ve folllowed @ibtissambth steps but still get error

this is the log

0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/Cellar/node/8.4.0/bin/node',
1 verbose cli   '/usr/local/bin/npm',
1 verbose cli   'run',
1 verbose cli   'development' ]
2 info using npm@5.4.1
3 info using node@v8.4.0
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/gama/Workspace/web/gama.web.id/node_modules/.bin:/usr/local/lib/node_modules/npm/bin/node-gyp-bin:/Users/gama/Workspace/web/gama.web.id/node_modules/.bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/Wireshark.app/Contents/MacOS:/Users/gama/Workspace/go:/Users/gama/Library/Android/sdk/tools:/Users/gama/Library/Android/sdk/platform-tools:/usr/local/Cellar/graphicsmagick/1.3.26_1/bin
9 verbose lifecycle @~development: CWD: /Users/gama/Workspace/web/gama.web.id
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: 2  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 2
13 verbose stack     at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:280:16)
13 verbose stack     at emitTwo (events.js:125:13)
13 verbose stack     at EventEmitter.emit (events.js:213:7)
13 verbose stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack     at emitTwo (events.js:125:13)
13 verbose stack     at ChildProcess.emit (events.js:213:7)
13 verbose stack     at maybeClose (internal/child_process.js:927:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5)
14 verbose pkgid @
15 verbose cwd /Users/gama/Workspace/web/gama.web.id
16 verbose Darwin 16.7.0
17 verbose argv "/usr/local/Cellar/node/8.4.0/bin/node" "/usr/local/bin/npm" "run" "development"
18 verbose node v8.4.0
19 verbose npm  v5.4.1
20 error code ELIFECYCLE
21 error errno 2
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 2
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 [ 2, true ]

this is package.json

{
    "private": true,
    "scripts": {
        "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",
        "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": "npm run watch -- --watch-poll",
        "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",
        "prod": "npm run production",
        "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.16.2",
        "bootstrap-sass": "^3.3.7",
        "cross-env": "^5.0.1",
        "jquery": "^3.1.1",
        "laravel-mix": "^1.2.0",
        "lodash": "^4.17.4",
        "vue": "^2.1.10"
    }
}

Anyone have similiar issue?

Homestead user on Mac here - I tried everything that I found everywhere, and eventually decided to start fresh. So I upgraded Virtual Box, Vagrant and a fresh install of Homestead, then delete my node_modules folder and did a npm install and now it’s finally working. I only wasted like 4 hours.

For me I’m not that sure if upgrading to Node.js v7 from v4 helped but I just upgraded it, removed node_modules then run npm install. Afterwards running npm run dev becomes successful.