During my application's deploy process, running npm run production causes laravel-mix and/or webpack to hang at 91% additional asset processing, and then exits to the command line without completing asset compilation. This issue has been mentioned on the webpack issue tracker and has been closed, but I can't seem to figure out what the actual solution is for a laravel-mix user, aside from updating everything to the latest version(s) which did not seem to help. I believe this is occurring because I have a very large SPA project with many Vue components and it is running out of memory while minifying/concatenating everything. (Running npm run dev works fine.) I don't know enough about webpack personally, I just use laravel-mix.
Large single-page-app project with lots of Vue components and vue-router. (Sorry I cannot provide this.)
Use the following package.json file:
{
"private": true,
"scripts": {
"dev": "cross-env NODE_ENV=development webpack --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch": "cross-env NODE_ENV=development webpack --watch --watch-poll --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"hot": "cross-env NODE_ENV=development webpack-dev-server --watch-poll --inline --hot --output-public-path http://myapp.local/ --host myapp.local --config=node_modules/laravel-mix/setup/webpack.config.js",
"production": "cross-env NODE_ENV=production webpack --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
},
"devDependencies": {
"axios": "^0.15.2",
"bootstrap": "^3.3.7",
"bootstrap-sass": "^3.3.7",
"jquery": "^3.2.1",
"laravel-mix": "^1.0.3",
"lodash": "^4.16.2",
"pusher-js": "^4.0.0",
"select2": "^4.0.3",
"vue": "^2.2.6",
"vue-multiselect": "^2.0.0-beta.15",
"vue-resource": "^1.3.1",
"vue-router": "^2.4.0"
},
"dependencies": {
"cross-env": "^5.0.1",
"laravel-echo": "^1.3.0",
"moment": "^2.18.1",
"moment-timezone": "^0.5.13",
"rrule": "^2.2.0",
"webpack": "^3.0.0"
},
"peerDependencies": {
"webpack": "^2.2.0"
}
}
npm run production to compile all assets.As a side note, the package.json file above also gives me issues with unmet peer dependencies when I run npm list --depth=0. I see an UNMET PEER DEPENDENCY for [email protected] but also npm ERR! peer dep missing: webpack@^2.2.0 for multiple other packages. This is why I was trying to include them both somehow, but I don't know how to install multiple versions of webpack the correct way to meet these peer dependencies.
Check if your Ubuntu server has a pagefile. Like you have mentioned that it could be a lack of memory.
@ruchern It's a default Amazon EC2 instance, and apparently they don't have swap files enabled by default. (Running swapon -s gives an empty result.) I will look into setting up swap on it. Meanwhile, I'm wondering if there is any laravel-mix or webpack configuration that can take care of this, as well.
Create a swapfile 2x the size of the phyiscal ram.
Meanwhile, I'm wondering if there is any laravel-mix or webpack configuration that can take care of this, as well.
I don't think laravel-mix or webpack has anything to do with this. It is definitely a lack of ram where npm actually needs.
I don't think
laravel-mixorwebpackhas anything to do with this. It is definitely a lack of ram wherenpmactually needs.
@ruchern You sure about that? This webpack issue comment says that "reading the string content should be avoided until you are done appending" -- so probably a webpack issue more than laravel-mix issue. I am just hoping that laravel-mix picks up the version of webpack that contains the fix, which is supposedly already fixed.
In the meantime, dealing with the memory on the server setup is, of course, always an appropriate thing to consider.
Ok, so I did two things to remedy this situation:
npm run production is run locally and then rsynced to the server. This alone solved the problem, but since memory was an issue and there was no swap enabled, I also...Things are working now, although I did step 1 first, so I haven't had a chance to confirm that the swap alone would resolve it.
@shorlbeck It happened to me on my production server where I only had 512MB of RAM. I added a 2 GB swapfile and the compiling continued past 91% additional asset processing.
Might be related: https://www.digitalocean.com/community/questions/npm-gets-killed-no-matter-what
Anyone coming back to this page, I can confirm creating swapfile fixed the problem for me.
OS: Ubuntu 18.04.3 LTS
Node: 10.17.0
NPM: 6.11.3
Laravel-mix: 2.1.14
RAM: 4GB
Swap: 4GB
Most helpful comment
@shorlbeck It happened to me on my production server where I only had 512MB of RAM. I added a 2 GB swapfile and the compiling continued past
91% additional asset processing.Might be related: https://www.digitalocean.com/community/questions/npm-gets-killed-no-matter-what