Laravel-mix: Error when 'npm run production'

Created on 26 May 2017  ·  10Comments  ·  Source: JeffreyWay/laravel-mix

Help, pleace... Whole day headache :(

Description: Error when 'npm run production'

> npm ERR! Darwin 16.5.0
> npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "production"
> npm ERR! node v6.10.3
> npm ERR! npm  v3.10.10
> npm ERR! code ELIFECYCLE
> npm ERR! @ production: `cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js`
> npm ERR! Exit status 2
> npm ERR! 
> npm ERR! Failed at the @ production script 'cross-env NODE_ENV=production 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=production 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!     /Users/valentin/Desktop/www/jobs/npm-debug.log

===========
npm-debug.log:

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   'production' ]
2 info using [email protected]
3 info using [email protected]
4 verbose run-script [ 'preproduction', 'production', 'postproduction' ]
5 info lifecycle @~preproduction: @
6 silly lifecycle @~preproduction: no script for preproduction, continuing
7 info lifecycle @~production: @
8 verbose lifecycle @~production: unsafe-perm in lifecycle true
9 verbose lifecycle @~production: PATH: /usr/local/lib/node_modules/npm/bin/node-gyp-bin:/Users/valentin/Desktop/www/jobs/node_modules/.bin:/Applications/MAMP/bin/php/php7.0.15/bin:vendor/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/valentin/.composer/vendor/bin:/Users/valentin/bin:/Users/valentin/.composer/vendor/bin
10 verbose lifecycle @~production: CWD: /Users/valentin/Desktop/www/jobs
11 silly lifecycle @~production: Args: [ '-c',
11 silly lifecycle   'cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js' ]
12 silly lifecycle @~production: Returned: code: 2  signal: null
13 info lifecycle @~production: Failed to exec production script
14 verbose stack Error: @ production: `cross-env NODE_ENV=production 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.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/lifecycle.js:255:16)
14 verbose stack     at emitTwo (events.js:106:13)
14 verbose stack     at EventEmitter.emit (events.js:191:7)
14 verbose stack     at ChildProcess.<anonymous> (/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:191:7)
14 verbose stack     at maybeClose (internal/child_process.js:886:16)
14 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)
15 verbose pkgid @
16 verbose cwd /Users/valentin/Desktop/www/jobs
17 error Darwin 16.5.0
18 error argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "production"
19 error node v6.10.3
20 error npm  v3.10.10
21 error code ELIFECYCLE
22 error @ production: `cross-env NODE_ENV=production 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 @ production script 'cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js'.
23 error Make sure you have the latest version of node.js and npm installed.
23 error If you do, this is most likely a problem with the  package,
23 error not with npm itself.
23 error Tell the author that this fails on your system:
23 error     cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js
23 error You can get information on how to open an issue for this project with:
23 error     npm bugs
23 error Or if that isn't available, you can get their info via:
23 error     npm owner ls
23 error There is likely additional logging output above.
24 verbose exit [ 1, true ]

Most helpful comment

@lotestudio
I fixed it by adding this to a newly created file .babelrc
{"presets": [ ["env", { "targets": { "uglify": false } }] ]}

All 10 comments

Update your cross-env and see if it works?

It's now 5.0.0 while yours is still at 3.2.4

Nope :(

same here just installed

npm run watch works fine but
npm run prod throws error

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

95% emitting

ERROR Failed to compile with 4 errors

error

/js/_users.js from UglifyJs

Unexpected token: punc (() [/js/users.js:48382,11]
```

@lotestudio
I fixed it by adding this to a newly created file .babelrc
{"presets": [ ["env", { "targets": { "uglify": false } }] ]}

Do you use Yarn or npm shrinkwrap by any chance?

It may be that some locked dependencies haven't updated properly. Try to delete node_modules folder and then do simple stupid npm install.

I had ELIFECYCLE error after upgrading to 0.12, Then if I recall correctly I performed the following sequence of actions:

yarn remove laravel-mix
yarn add laravel-mix
yarn remove cross-env
yarn add cross-env

Weirdly, the issue was gone after purging the old cross-env.

@adiachenko I use npm, but will try the sequence.
@msonowal same with with watch and production.

Hm...I've found that laravel notification in upper right corner produce warning: 'undefined/app.someversioncontrolnumber.js'.
Here is my webpack.mix.js:

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

mix.setPublicPath('public_html/');

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

mix.browserSync('jobs');

if (mix.config.inProduction) {
    mix.version();
}

The vue-strap library caused the problem. There is some files that babel can't compile for some reason. I've complied them manually with babel online compiler and everything work now. Still don't understand the problem entirety. The errors in command line is not so clear, but notification panel from laravel mix show me the exact error. Is there some explanation why mix can't compile these files?

Hi @lotestudio . Did you find any answer to your question "Is there some explanation why mix can't compile these files?" ? Because I ran into the very same problem (for another vue npm package but basically the same problem). I'm pretty sure that if I change the file by hand to make it readable in JS it'll work but I'd prefer not to touch to npm dependencies in my project and I can't figure out how to solve this O_O

@msonowal after spending hours and hours and hours with this issue, your solution fixed everything like a charm! Thanks a lot!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jpmurray picture jpmurray  ·  3Comments

wendt88 picture wendt88  ·  3Comments

rlewkowicz picture rlewkowicz  ·  3Comments

Bomavi picture Bomavi  ·  3Comments

terion-name picture terion-name  ·  3Comments