Laravel-mix: `npm run dev` cross-env error

Created on 13 May 2017  路  17Comments  路  Source: JeffreyWay/laravel-mix

Laravel 5.4.23
Node.js version: 7.7.2
npm version: 4.1.2
LaraDock on Ubuntu 16.04

laradock@10e308159f66:/var/www$ npm run dev

Here is the error:

> @ dev /var/www
> npm run development

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

undefined:1

SyntaxError: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at Manifest.read (/var/www/node_modules/laravel-mix/src/Manifest.js:138:21)
    at new Manifest (/var/www/node_modules/laravel-mix/src/Manifest.js:9:43)
    at Mix.initialize (/var/www/node_modules/laravel-mix/src/Mix.js:27:25)
    at Object.<anonymous> (/var/www/node_modules/laravel-mix/setup/webpack.config.js:35:5)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)

npm ERR! Linux 4.9.14-200.fc25.x86_64
npm ERR! argv "/home/laradock/.nvm/versions/node/v7.7.2/bin/node" "/home/laradock/.nvm/versions/node/v7.7.2/bin/npm" "run" "development"
npm ERR! node v7.7.2
npm ERR! npm  v4.1.2
npm ERR! code ELIFECYCLE
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 '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! 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 --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!     /var/www/npm-debug.log

npm ERR! Linux 4.9.14-200.fc25.x86_64
npm ERR! argv "/home/laradock/.nvm/versions/node/v7.7.2/bin/node" "/home/laradock/.nvm/versions/node/v7.7.2/bin/npm" "run" "dev"
npm ERR! node v7.7.2
npm ERR! npm  v4.1.2
npm ERR! code ELIFECYCLE
npm ERR! @ dev: `npm run development`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the @ dev script 'npm run development'.
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!     npm run development
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!     /var/www/npm-debug.log

And Here 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.15.3",
    "bootstrap-sass": "^3.3.7",
    "cross-env": "^3.2.3",
    "jquery": "^3.1.1",
    "laravel-mix": "0.*",
    "lodash": "^4.17.4",
    "vue": "^2.1.10"
  }
}

Most helpful comment

I removed node_modules, then npm install --global cross-env, followed by removing cross-env from package.json, then npm run dev worked.

All 17 comments

Problem solved after I removed:

public/mix-manifest.json

I'm facing the exact same issue but removing public/mix-manifest.json didn't fix it.. Here is my log...

Laravel 5.4.22
Node.js version: 7.1.0
npm version: 4.2.0
no homestead or laradock

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 [email protected]
3 info using [email protected]
4 verbose run-script [ 'predevelopment', 'development', 'postdevelopment' ]
5 info lifecycle @~predevelopment: @
6 silly lifecycle @~predevelopment: no script for predevelopment, continuing
7 info lifecycle @~development: @
8 verbose lifecycle @~development: unsafe-perm in lifecycle true
9 verbose lifecycle @~development: PATH: /usr/local/lib/node_modules/npm/bin/node-gyp-bin:/home/vignesh/workspace/appointment/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
10 verbose lifecycle @~development: CWD: /home/vignesh/workspace/appointment
11 silly lifecycle @~development: Args: [ '-c',
11 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' ]
12 silly lifecycle @~development: Returned: code: 2 signal: null
13 info lifecycle @~development: Failed to exec development script
14 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
14 verbose stack Exit status 2
14 verbose stack at EventEmitter. (/usr/local/lib/node_modules/npm/lib/utils/lifecycle.js:279:16)
14 verbose stack at emitTwo (events.js:106:13)
14 verbose stack at EventEmitter.emit (events.js:194:7)
14 verbose stack at ChildProcess. (/usr/local/lib/node_modules/npm/lib/utils/spawn.js:40:14)
14 verbose stack at emitTwo (events.js:106:13)
14 verbose stack at ChildProcess.emit (events.js:194:7)
14 verbose stack at maybeClose (internal/child_process.js:899:16)
14 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)
15 verbose pkgid @
16 verbose cwd /home/vignesh/workspace/appointment
17 error Linux 3.19.0-32-generic
18 error argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "development"
19 error node v7.10.0
20 error npm v4.2.0
21 error code ELIFECYCLE
22 error errno 2
23 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
23 error Exit status 2
24 error Failed at the @ development script 'cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js'.
24 error Make sure you have the latest version of node.js and npm installed.
24 error If you do, this is most likely a problem with the package,
24 error not with npm itself.
24 error Tell the author that this fails on your system:
24 error cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js
24 error You can get information on how to open an issue for this project with:
24 error npm bugs
24 error Or if that isn't available, you can get their info via:
24 error npm owner ls
24 error There is likely additional logging output above.
25 verbose exit [ 2, true ]

UPDATE :

Fixed issue by running npm install --global cross-env

I removed node_modules, then npm install --global cross-env, followed by removing cross-env from package.json, then npm run dev worked.

Does not work for me. Within 麓node_modules麓 there is no directory 麓webpack麓. Where should it come from?

+1

@Elypson Try installing webpack under global npm.

npm i -g webpack@latest

@ruchern Tried that, with no success. But removing composer.pack and then using composer again helped

@Elypson That's funny. Composer is a PHP package manager rather than a Node package manager. It should and by right not create the problems. However, it worked for you so it's good.

I figured that I had not ran npm install, so it threw a similar problem, just posting it here incase this fixes for others.

Had to do chmod -R u+x . in the root folder of the project to get it to work. Tried everything above but of course you need the right permissions to start with!

none of the solutions work for me..

None of above solution is work for me..can you guys tell me what to do actually to get it work.....

Deleting package-lock.json & node_modules/ folder and running npm install worked for me

I have same issue at my, version laravel 7x ubuntu 18
I did get the packege.json of the top and it woking now.
But is one version more old.

Had the same issue with Laravel8.
npm ERR! @ development: cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --config=node_modules/laravel-mix/setup/webpack.config.js

_npm install --global cross-env_ - solved my problem

Kind of funny because cross-env is listed under "devDependencies" but is actually needed to run the "production" script

Two things:

  1. We recommend using the new mix executable with mix 6 as it handles some setup for you.
  2. Once we tag the next release cross-env won't be necessary at all. However, cross-env has been in dependencies not devDependencies:

Screen Shot 2021-02-02 at 22 36 02

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Micaso picture Micaso  路  3Comments

dtheb picture dtheb  路  3Comments

stefensuhat picture stefensuhat  路  3Comments

nezaboravi picture nezaboravi  路  3Comments

sdebacker picture sdebacker  路  3Comments