[vercel/next.js]致命错误:CALL_AND_RETRY_LAST 分配失败 - JavaScript 堆内存不足

2024-05-15 314 views
4
错误报告 描述错误

如果我运行开发服务器并打开几个小时。服务器自动关闭并显示此错误消息。

<--- Last few GCs --->

[42587:0x102801e00]  4108743 ms: Mark-sweep 1369.0 (1417.2) -> 1369.0 (1421.2) MB, 558.5 / 0.0 ms  allocation failure GC in old space requested
[42587:0x102801e00]  4109472 ms: Mark-sweep 1369.0 (1421.2) -> 1369.0 (1413.2) MB, 729.2 / 0.0 ms  last resort GC in old space requested
[42587:0x102801e00]  4109969 ms: Mark-sweep 1369.0 (1413.2) -> 1369.0 (1413.2) MB, 497.1 / 0.0 ms  last resort GC in old space requested

<--- JS stacktrace --->

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

Security context: 0x19c4f6125879 <JSObject>
    1: add [/Users/steve/juven/frontend/node_modules/hard-source-webpack-plugin/lib/SerializerAppend2.js:~71] [pc=0x1bb0948a8aa](this=0x19c4e8bde1f9 <WriteOutput map = 0x19c48d594f79>,key=0x19c4e32749c1 <String[61]: 1B2M2Y8AsgTpgAmY7PhCfg==node_modules/rc-animate/es/Animate.js>,content=0x19c4e8bb12e1 <Very long string[308078]>)
    2: write [/Users/steve/frontend/node_modules/hard-source-w...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
 1: node::Abort() [/Users/steve/.nvm/versions/node/v8.12.0/bin/node]
 2: node::FatalException(v8::Isolate*, v8::Local<v8::Value>, v8::Local<v8::Message>) [/Users/steve/.nvm/versions/node/v8.12.0/bin/node]
 3: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [/Users/steve/.nvm/versions/node/v8.12.0/bin/node]
 4: v8::internal::Factory::NewRawTwoByteString(int, v8::internal::PretenureFlag) [/Users/steve/.nvm/versions/node/v8.12.0/bin/node]
 5: v8::internal::String::SlowFlatten(v8::internal::Handle<v8::internal::ConsString>, v8::internal::PretenureFlag) [/Users/steve/.nvm/versions/node/v8.12.0/bin/node]
 6: v8::String::WriteUtf8(char*, int, int*, int) const [/Users/steve/.nvm/versions/node/v8.12.0/bin/node]
 7: node::StringBytes::Write(v8::Isolate*, char*, unsigned long, v8::Local<v8::Value>, node::encoding, int*) [/Users/steve/.nvm/versions/node/v8.12.0/bin/node]
 8: void node::Buffer::(anonymous namespace)::StringWrite<(node::encoding)1>(v8::FunctionCallbackInfo<v8::Value> const&) [/Users/steve/.nvm/versions/node/v8.12.0/bin/node]
 9: 0x1bb0710a5c7
10: 0x1bb0948a8aa
error Command failed with signal "SIGABRT".
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
重现

没有把握。只需打开开发服务器几个小时

预期行为

服务器不应关闭

截图

如果适用,请添加屏幕截图以帮助解释您的问题。

系统信息
  • 操作系统: mac
  • 浏览器镀铬
  • Next.js 版本:7.0.0
额外的背景信息

在此处添加有关该问题的任何其他上下文。

回答

8

不知道在没有复制的情况下该怎么办。所以我要关闭这个问题。

8

FWIW 我也在 Next @7 上看到了这个。诊断有点困难,但我很乐意分享像我的next.config.babelrc.

4

你好@pruhstal - 你能解决这个问题吗?

8

与最新的 next.js 类似的问题

RangeError: "size" argument must not be larger than 2147483647
    at Function.Buffer.allocUnsafe (buffer.js:253:3)
    at alloc (/Users/jamesgardner/src/project/app/node_modules/hard-source-webpack-plugin/lib/SerializerAppend2.js:46:17)
    at Append2._readFile (/Users/jamesgardner/src/project/app/node_modules/hard-source-webpack-plugin/lib/SerializerAppend2.js:160:14)
    at <anonymous>

<--- Last few GCs --->

[14301:0x103000000]     6211 ms: Mark-sweep 819.3 (832.0) -> 819.3 (831.0) MB, 57.0 / 0.0 ms  allocation failure GC in old space requested
[14301:0x103000000]     6252 ms: Mark-sweep 819.3 (831.0) -> 819.1 (828.0) MB, 40.8 / 0.0 ms  last resort GC in old space requested
[14301:0x103000000]     6278 ms: Mark-sweep 819.1 (828.0) -> 819.1 (828.0) MB, 26.7 / 0.0 ms  last resort GC in old space requested

<--- JS stacktrace --->

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

Security context: 0x35f55f7a5879 <JSObject>
    1: _readFile [/Users/jamesgardner/src/project/app/node_modules/hard-source-webpack-plugin/lib/SerializerAppend2.js:167] [bytecode=0x35f56c0d1b01 offset=422](this=0x35f521c59649 <Append2 map = 0x35f5ff291821>,file=0x35f5ebe02311 <the_hole>)
    2: /* anonymous */(this=0x35f52c504e39 <JSGlobal Object>,9)
    3: /* anonymous */(aka /* anonymous */)(this=0x35f5ebe022d1 <undefined...

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::NewRawOneByteString(int, v8::internal::PretenureFlag) [/usr/local/bin/node]
 5: v8::internal::Factory::NewStringFromUtf8(v8::internal::Vector<char const>, v8::internal::PretenureFlag) [/usr/local/bin/node]
 6: v8::String::NewFromUtf8(v8::Isolate*, char const*, v8::NewStringType, int) [/usr/local/bin/node]
 7: node::StringBytes::Encode(v8::Isolate*, char const*, unsigned long, node::encoding, v8::Local<v8::Value>*) [/usr/local/bin/node]
 8: void node::Buffer::(anonymous namespace)::StringSlice<(node::encoding)1>(v8::FunctionCallbackInfo<v8::Value> const&) [/usr/local/bin/node]
 9: v8::internal::FunctionCallbackArguments::Call(void (*)(v8::FunctionCallbackInfo<v8::Value> const&)) [/usr/local/bin/node]
10: v8::internal::MaybeHandle<v8::internal::Object> v8::internal::(anonymous namespace)::HandleApiCallHelper<false>(v8::internal::Isolate*, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::FunctionTemplateInfo>, v8::internal::Handle<v8::internal::Object>, v8::internal::BuiltinArguments) [/usr/local/bin/node]
11: v8::internal::Builtin_Impl_HandleApiCall(v8::internal::BuiltinArguments, v8::internal::Isolate*) [/usr/local/bin/node]
12: 0x1e54124842fd
13: 0x1e541253d1d6

我曾经用 来解决这个问题,npm clean cache --force但自从我升级到最新的 npm 后,它就不起作用了。

0

@sasindroid 还没有,但我最近运行服务器的时间还不够长,无法进行复制。当再次发生这种情况时,我会发布更新。

0

@sasindroid 又发生了。 @^7.0.2

<--- Last few GCs --->

[37728:0x102801000]  8389263 ms: Mark-sweep 1388.5 (1464.0) -> 1388.4 (1464.0) MB, 456.9 / 0.0 ms  allocation failure GC in old space requested
[37728:0x102801000]  8389805 ms: Mark-sweep 1388.4 (1464.0) -> 1388.4 (1431.0) MB, 541.7 / 0.0 ms  last resort GC in old space requested
[37728:0x102801000]  8390320 ms: Mark-sweep 1388.4 (1431.0) -> 1388.4 (1430.5) MB, 514.8 / 0.0 ms  last resort GC in old space requested

<--- JS stacktrace --->

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

Security context: 0xf9978125501 <JSObject>
    1: push(this=0xf990d40aef1 <JSArray[50855]>)
    2: /* anonymous */(aka /* anonymous */) [/Users/me/Sites/node_modules/@babel/core/lib/transformation/file/merge-map.js:~155] [pc=0x167f491c5acb](this=0xf9965f02201 <null>,m=0xf998df5b631 <Object map = 0xf997e2193e1>)
    3: arguments adaptor frame: 3->1
    4: forEach(this=0xf998ae06b79 <JSArray[89656]>)
    5: eachMapping(aka Sourc...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
 1: node::Abort() [/Users/me/.nvm/versions/node/v9.7.1/bin/node]
 2: node::FatalTryCatch::~FatalTryCatch() [/Users/me/.nvm/versions/node/v9.7.1/bin/node]
 3: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [/Users/me/.nvm/versions/node/v9.7.1/bin/node]
 4: v8::internal::Factory::NewUninitializedFixedArray(int) [/Users/me/.nvm/versions/node/v9.7.1/bin/node]
 5: v8::internal::(anonymous namespace)::ElementsAccessorBase<v8::internal::(anonymous namespace)::FastPackedObjectElementsAccessor, v8::internal::(anonymous namespace)::ElementsKindTraits<(v8::internal::ElementsKind)2> >::ConvertElementsWithCapacity(v8::internal::Handle<v8::internal::JSObject>, v8::internal::Handle<v8::internal::FixedArrayBase>, v8::internal::ElementsKind, unsigned int, unsigned int, unsigned int, int) [/Users/me/.nvm/versions/node/v9.7.1/bin/node]
 6: v8::internal::(anonymous namespace)::ElementsAccessorBase<v8::internal::(anonymous namespace)::FastPackedObjectElementsAccessor, v8::internal::(anonymous namespace)::ElementsKindTraits<(v8::internal::ElementsKind)2> >::GrowCapacityAndConvertImpl(v8::internal::Handle<v8::internal::JSObject>, unsigned int) [/Users/me/.nvm/versions/node/v9.7.1/bin/node]
 7: v8::internal::(anonymous namespace)::ElementsAccessorBase<v8::internal::(anonymous namespace)::FastPackedObjectElementsAccessor, v8::internal::(anonymous namespace)::ElementsKindTraits<(v8::internal::ElementsKind)2> >::Add(v8::internal::Handle<v8::internal::JSObject>, unsigned int, v8::internal::Handle<v8::internal::Object>, v8::internal::PropertyAttributes, unsigned int) [/Users/me/.nvm/versions/node/v9.7.1/bin/node]
 8: v8::internal::JSObject::AddDataElement(v8::internal::Handle<v8::internal::JSObject>, unsigned int, v8::internal::Handle<v8::internal::Object>, v8::internal::PropertyAttributes, v8::internal::Object::ShouldThrow) [/Users/me/.nvm/versions/node/v9.7.1/bin/node]
 9: v8::internal::Runtime_SetProperty(int, v8::internal::Object**, v8::internal::Isolate*) [/Users/me/.nvm/versions/node/v9.7.1/bin/node]
10: 0x167f3cb042fd
Abort trap: 6

使用"@babel/core": "^7.2.2"and "babel-core": "^7.0.0-bridge.0"and 我有预感它与 babel 有关。

3

生产环境又出现了。

0

“在生产环境中又发生了。”从我们这边来说,这并不是真正可行的。请提供副本,以便我们进行调查。

3

从 NextJS 6 升级到 NextJS 8 后,我遇到了内存不足错误,chrome 开发工具内存选项卡表明这与styled-components.

我将此问题的发生与 的使用隔离开来<Text is={Flex}/>,这两个组件都来自rebass@v2

删除这个用法解决了我的问题。

8

确实是。谢谢。

6

9

看到同样的问题。常见的 Node.js 解决方案似乎使用

--max-old-space-size

构建上的标志。如何将该标志注入到现在的构建中?

6

您可以通过设置NODE_OPTIONS来做到这一点。

IE)

"script": {
  "build": "NODE_OPTIONS=--max_old_space_size=4096 next build"
}

必须深入挖掘 40-50 个网页才能解决这个该死的“内存不足”问题,并找出如何通过npm 脚本为节点提供更多内存。

另请注意,这并没有发生在我本地的 MacBook(16GB 内存)上。然而,在我们的 jenkin t2.medium ec2 实例(只有 4GB 内存)上不断遇到这个问题。

资源 - https://github.com/npm/npm/issues/12238#issuecomment-367147962

不客气,codestas'

7

@brothatru,我正在尝试执行此操作,但 mac 上的内存仍然不足,您知道我缺少什么吗? scripts": { "dev": "NODE_OPTIONS=--max_old_space_size=8096 npm run development", }

3

在 Next 9 的开发和生产中,这种情况仍然发生。增加max_old_space_size并不是解决问题的办法。为什么node要占用这么多内存?

9

也许你的代码效率不高,或者你引用的 util 不起作用,或者是由不正确的引用/使用引起的;但更多时候,是因为node_modules(例如,hard-source-webpack-plugin)。这就是导致你的内存被耗尽的原因。

解决方案 :

  • 找出它占用内存的原因并修复它(node_modules例如创建无限循环的代码)。
  • max_old_space_size
4

由于最近没有活动,此问题已被自动锁定。如果您遇到类似问题,请创建一个新问题并包含重现步骤。谢谢。