vue项目运行时报内存溢出:JavaScript heap out of memory

原文链接:https://blog.csdn.net/u014028247/article/details/120198702

==== JS stack trace =========================================

    0: ExitFrame [pc: 000002AACBF079E0]
Security context: 0x00b4d151e6e9 
    1: byteLength(aka byteLength) [000000CEB10F80D9] [buffer.js:~509] [pc=000002AACE049EB0](this=0x038bfc4826f1 ,string=0x00fee4577be1 ,encoding=0x00b4d153e311 )
    2: arguments adaptor frame: 3->2
    3: fromString(aka fromString) [0000025E642117B9] [buffer.js:~334] [pc=000002AACE2A0EF0](this=0x038b...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
 1: 00007FF774B6F04A v8::internal::GCIdleTimeHandler::GCIdleTimeHandler+5114
 2: 00007FF774B4A0C6 node::MakeCallback+4518
 3: 00007FF774B4AA30 node_module_register+2032
 4: 00007FF774DD20EE v8::internal::FatalProcessOutOfMemory+846
 5: 00007FF774DD201F v8::internal::FatalProcessOutOfMemory+639
 6: 00007FF7752F2BC4 v8::internal::Heap::MaxHeapGrowingFactor+9556
 7: 00007FF7752F10CB v8::internal::Heap::MaxHeapGrowingFactor+2651
 8: 00007FF774EACA3B v8::internal::Factory::AllocateRawWithImmortalMap+59
 9: 00007FF774EAF4ED v8::internal::Factory::NewRawTwoByteString+77
11: 00007FF774DC582B v8::internal::StringHasher::UpdateIndex+219
12: 00007FF774DEAB26 v8::String::Utf8Length+22
13: 00007FF774B3370C node::Buffer::New+4332
14: 000002AACBF079E0
npm ERR! code ELIFECYCLE
npm ERR! errno 134

记录一下解决办法:

1、在package.json中添加如下配置,

"dependencies": {

        "increase-memory-limit": "^1.0.3",

        "cross-env": "^5.0.5"

},

2、执行

  npm install increase-memory-limit 或(pnpm install increase-memory-limit)

  npm i cross-env --save-dev 或( npm i cross-env --save-dev )

3、 在package.json中添加如下配置,

"scripts": {
    "fix-memory-limit": "cross-env LIMIT=3072  increase-memory-limit"
  },

LIMIT是分配的内存大小,有3027、4096、8192、10240,

4、配置完之后执行

npm run fix-memory-limit

3、执行npm run dev 时如果报错:

'"node --max-old-space-size=3072"' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

解决办法:

在项目中 node_modules.bin 下的 webpack.cmd 和 webpack-dev-server.cmd文件中

去掉双引号, 修改"%_prog%" 为 %_prog%,即可正常运行

你可能感兴趣的:(javascript,vue.js,开发语言)