解决前端vue项目由于项目太大导致的JavaScript heap out of memory错误

解决前端vue项目由于项目太大导致的JavaScript heap out of memory错误

    • 报错信息
    • 尝试解决方式一
    • 尝试解决方式二
    • 尝试解决方式三

报错信息

Security context: 0x2ea3c325879 <JSObject>
    1: fromString(aka fromString) [buffer.js:~298] [pc=0xca9c42d81e9](this=0x2ea147822d1 <undefined>,string=0x2eaf5199591 <Very long string[1878590]>,encoding=0x2ea3c3358e9 <String[4]: utf8>)
    2: from [buffer.js:177] [bytecode=0x2eafc474791 offset=11](this=0x2ea362b64f1 <JSFunction Buffer (sfi = 0x2ea3c37c461)>,value=0x2eaf5199591 <Very long string[1878590]>,encodingOrOffset=0x2ea3c3358e9 <Str...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
 1: node::Abort() [/usr/local/bin/node]
 2: node::FatalException(v8::Isolate*, v8::Local<v8::Value>, v8::Local<v8::Message>) [/usr/local/bin/node]
 3: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [/usr/local/bin/node]
 4: v8::internal::Factory::NewRawTwoByteString(int, v8::internal::PretenureFlag) [/usr/local/bin/node]
 5: v8::internal::String::SlowFlatten(v8::internal::Handle<v8::internal::ConsString>, v8::internal::PretenureFlag) [/usr/local/bin/node]
 6: v8::String::WriteUtf8(char*, int, int*, int) const [/usr/local/bin/node]
 7: node::StringBytes::Write(v8::Isolate*, char*, unsigned long, v8::Local<v8::Value>, node::encoding, int*) [/usr/local/bin/node]
 8: node::Buffer::New(v8::Isolate*, v8::Local<v8::String>, node::encoding) [/usr/local/bin/node]
 9: node::Buffer::(anonymous namespace)::CreateFromString(v8::FunctionCallbackInfo<v8::Value> const&) [/usr/local/bin/node]
10: 0xca9c314db47
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! link-front-webpack@1.0.0 dev: `cross-env NODE_ENV=dev webpack-dev-server --inline --progress --config build/webpack.dev.conf.js `
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the link-front-webpack@1.0.0 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!     /Users/leonard/.npm/_logs/2020-08-03T17_35_29_005Z-debug.log
Hand-Jingld-MacBook-Pro:link-front leonard$ 
Hand-Jingld-MacBook-Pro:link-front leonard$ npm install -g increase-memory-limit
/usr/local/bin/increase-memory-limit -> /usr/local/lib/node_modules/increase-memory-limit/index.js
+ increase-memory-limit@1.0.7
updated 1 package in 0.227s
Hand-Jingld-MacBook-Pro:link-front leonard$ npm run fix-memroy-limit
npm ERR! missing script: fix-memroy-limit
npm ERR! 
npm ERR! Did you mean this?
npm ERR!     fix-memory-limit

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/leonard/.npm/_logs/2020-08-04T01_22_12_259Z-debug.log

尝试解决方式一

安装increase-memory-limit插件增大内存,执行成功后,此问题尚未解决。(其他同事使用此方式后没有再报错)

尝试解决方式二

修改pakage.json文件scripts部分,增大mas_old_space_size

"build": "cross-env BUILD_ENV=dev node --max_old_space_size=8192 build/build.js && cross-env BUILD_ENV=dev node src/plain_html/config/buildforwebpack.js"

此方式也未能解决问题。

尝试解决方式三

执行:
npm i increase-memory-limit --save-dev
npm i cross-env --save-dev
修改pakage.json文件,在scripts下增加如下:

"fix-memroy-limit": "cross-env LIMIT=4096 increase-memory-limit",

执行:
npm run fix-memroy-limit
使用此种方式,重新编译运行后成功。

你可能感兴趣的:(前端,vue.js,javascript,intellij,idea)