vue-cli: yarn serve - JavaScript heap out of memory crash
Version
3.0.0-beta.15
Reproduction link
https://github.com/xrei/vuecli-bug
Steps to reproduce
Well… it’s not hard to reproduce but takes time.
Run yarn serve
and develop for some hours 😃
What is expected?
Stable working dev server
What is actually happening?
After some hours (~1-2) dev server will crash with an error:
95% emitting CopyPlugin
<--- Last few GCs --->
[2032:000001F314F3C8F0] 5471846 ms: Mark-sweep 1381.6 (1414.7) -> 1381.6 (1414.7) MB, 250.8 / 0.0 m
s allocation failure GC in old space requested
[2032:000001F314F3C8F0] 5472120 ms: Mark-sweep 1381.6 (1414.7) -> 1381.6 (1413.7) MB, 273.5 / 0.0 m
s last resort GC in old space requested
[2032:000001F314F3C8F0] 5472433 ms: Mark-sweep 1381.6 (1413.7) -> 1381.6 (1413.7) MB, 313.7 / 0.0 m
s last resort GC in old space requested
<--- JS stacktrace --->
==== JS stack trace =========================================
0: ExitFrame [pc: 000001CC26384281]
Security context: 000002F26A1206A9 <JSObject>
1: fromString(aka fromString) [buffer.js:349] [bytecode=0000006AEF71E081 offset=148](this=000001
3071A022E1 <undefined>,string=0000031511A4D141 <Very long string[3793765]>,encoding=000002F26A131A29
<String[4]: utf8>)
2: from [buffer.js:201] [bytecode=0000006AEF71DC01 offset=11](this=0000023CE59638A9 <JSFunction
Buffer (sfi = 0000037B38A8B959)>,val...
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
1: node::DecodeWrite
2: node_module_register
3: v8::internal::FatalProcessOutOfMemory
4: v8::internal::FatalProcessOutOfMemory
5: v8::internal::Heap::MaxHeapGrowingFactor
6: v8::internal::Factory::NewRawTwoByteString
7: v8::internal::Smi::SmiPrint
8: unibrow::Utf8DecoderBase::WriteUtf16Slow
9: v8::String::WriteUtf8
10: std::basic_ostream<char,std::char_traits<char> >::basic_ostream<char,std::char_traits<char> >
11: node::Buffer::New
12: node::Buffer::New
13: v8::internal::interpreter::BytecodeDecoder::Decode
14: v8::internal::RegExpImpl::Exec
15: v8::internal::RegExpImpl::Exec
16: v8::internal::RegExpImpl::Exec
17: 000001CC26384281
error Command failed with exit code 134.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 43
- Comments: 50 (11 by maintainers)
Commits related to this issue
- fix: increase Node memory limit to workaround webpack crash, fix #1453 — committed to octref/vue-cli by octref 6 years ago
- fix: increase Node memory limit to workaround webpack crash, fix #1453 — committed to octref/vue-cli by octref 6 years ago
- fix(cli-service): fix webpack memory leak (closes #1453) — committed to octref/vue-cli by octref 6 years ago
- build(project): try increase heap size as suggested here https://github.com/vuejs/vue-cli/issues/1453 — committed to moranje/meditor-one by moranje 6 years ago
- FIX the out of memory issue https://github.com/vuejs/vue-cli/issues/1453 — committed to storybookjs/storybook by ndelangen 5 years ago
- FIX the out of memory issue https://github.com/vuejs/vue-cli/issues/1453 — committed to storybookjs/storybook by ndelangen 5 years ago
- FIX the out of memory issue https://github.com/vuejs/vue-cli/issues/1453 — committed to storybookjs/storybook by ndelangen 5 years ago
"dev": "npx --max_old_space_size=4096 vue-cli-service serve"@atinybeardedman this worked for me
but just wanna say, that my own webpack config doesn’t have this issue with memory also i’m sure i have enough memory. just strange behaviour. maybe it’s because of webpack 4. I don’t know.
@xrei this is because of your code. for me , in my project , i have more than 500 pages and more 100 base components , and with a large assets and css with cssmodule. some bad practice with cssmodule from junior developer , this will take large memory. ( ´▽`)
There’s nothing vue-cli can do about this.
Adding a directory of large library files to my project’s
.eslintignorefile fixed the issue for me.I get this crash after about 10 saves and webpack tries to compile.
@octref we can do that for now. Although in the long run we probably want to see if there’s anything we can do to reduce the heap usage. I think it’s because a single Vue file actually involves multiple source maps being passed and merged.
Just in case anyone else finds this issue I had to change the package.json serve script to the following:
“serve” : “node --max_old_space_size=4096 node_modules/.bin/vue-cli-service serve --open”
@ryouaki your path didn’t work for me
change the scripts at package.json as below node --max_old_space_size=4096 node_modules/@vue/cli-service/bin/vue-cli-service.js serve --open
Any solution ?
solution:
npm i -D cross-env"scripts"; { "dev": "cross-env NODE_OPTIONS=--max_old_space_size=8192 vue-cli-service serve --mode development" }I’m still getting this crash as well - have tried the
--max_old_space_size=4096but still crashes after about 10 mins. The old vue-cli webpack worked great no problems at all. Any thoughts, solutions, anything???There is definitely a (large) memory leak causing yarn serve / npm serve to crash consistently and reproducibly. Yes, I can delay that crash somewhat by increasing memory for Node until my dev machine has swapped everything else out of RAM. Not sure why this issue is closed?
This memory leak is most egregious when I use web workers, I think since they bundle several npm libraries, and apparently the entire thing is then leaked. I can crash the
yarn serveprocess on my second build without fail, with my project’s particular combination of web workers, typescript, and babel. But I can see that that combo is not required for the memory leak to occur.Every time a file-save event triggers a build, the node process inches up in memory. (In my case it “inches up” by about 400k RAM on every save). I’ve bumped Node up to a max of 4GB of RAM which sometimes gets me through a couple hours of dev before it crashes.
I’d like to help find the actual cause. What can I do to help?
.eslintignoredoes not solve the problem for meHoping these details help us find a real solution!
for me worked even just
cross-env NODE_ENV=development vue-cli-service servethank youthis is not an issue from vue-cli ,this is the limit from nodejs.
edit package.json
“serve”:“node --max_old_space_size=4096 node_modules/@vue/cli-service/bin/vue-cli-service.js serve --open”
@yyx990803 You can fix this by adding
--max_old_space_size=4096to the hashbang of cli-service.I only had a small project that I developed for 3 hours, and this happened for at least 5 times. I feel a lot of people might run into this issue.
Root cause is here: https://github.com/webpack/webpack/issues/1914#issuecomment-392660230. From what I read in the thread, it seems to be that the memory usage from sourcemap generation & file watching hits V8’s limit (1400MB). Bumping the limit to 4GB should make the ceiling much harder to hit.
Well, not in every case can we enlarge the heap size easily. In my practice, i have apps (docker) built for both amd64, arm32v7. And the arm32v7 version is supposed to built on a Raspberry Pi 3B, which only got 1GB ram. It may take longer, but I will eventually get what I need. But when this error occurs, the whole RPi building toolchain fail to deliver.
@runxc1 , it throws below error:
i am using like below:
ok, just in case this is helpful to anyone…i got rid of this issue with
however turns out that vue-cli -service build command still has lots of problems with my npm linked package and unfortunately i cant figure out the correct webpack settings…but i guess thats a different story 😕
i’m currently used version is 3.0.0-beta.15(often crashed because of memory leaks), what can I do to upgrade to the new version(v3.0.0-rc.3)?
“build”: “node --max-old-space-size=8192 node_modules/vite/bin/vite.js build”,
So I see that this issue is closed but none of the fixes noted here in changing the package.json seem to fix the issue. I was using the Vue UI and am no longer able to and am starting to no longer be able to make more than 2 or 3 changes before it runs out of memory.
I am trying increase the memory for the following script
"build-watch": "vue-cli-service build --mode development --dest ../../wwwroot/vue --target app --watch"and get an error when I attempt to change it to"build-watch": "node --max_old_space_size=4096 node_modules/.bin/vue-cli-service build --mode development --dest ../../wwwroot/vue --target app --watch"@ryouaki I encounter this problem always, even use your workaround. But this problem’s gone when I disable eslint by [lintOnSave: false] in vue.config.js~~
I’m having similar issue with running some project using vue-cli-service as soon as I inject a local dev-version of a package to be used in that project using
npm link. Raising heap size didn’t work out. As soon as I publish the package on npm and replace the link with installation from npm repo everything is working as expected. Any clues on this?UPDATE: Ok, kept searching just a bit. And it looks like quite several tools around and including webpack were/are having issues with handling symlinked deps (according to this and all the issues linked there). That’s a bummer for trying to work with npm ecosystem e.g. by developing packages to be part of a VueJS project if there is no other way but fixing webpack configuration through vue CLI configuration the pretty hard way. What would be the best approach to control this from vue.config.js?
I’m also having this problem a few times / day after a few dozen of saves even when increasing the max_old_space_size=4096. I never had this problem using the old vue cli 2.9.x + webpack template and the default max_old_space_size. perhaps an upstream bug somewhere that is increasing the heap ?