如何使用 Next.js 为 Javascript 堆分配更多内存 [英] How to Allocate More Memory to Javascript Heap Using Next.js

查看:12
本文介绍了如何使用 Next.js 为 Javascript 堆分配更多内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的 Next.js 应用程序的开发环境有问题.

We're having a problem with the development environment of our Next.js app.

我们的 Javascript 堆经常耗尽内存.以下是具体的错误日志:

Our Javascript heap is constantly running out of memory. Here are the specific error logs:

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
 1: 0x10003ae75 node::Abort() [/usr/local/bin/node]
 2: 0x10003b07f node::OnFatalError(char const*, char const*) [/usr/local/bin/node]
 3: 0x1001a7ae5 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/usr/local/bin/node]
 4: 0x100572ef2 v8::internal::Heap::FatalProcessOutOfMemory(char const*) [/usr/local/bin/node]
 5: 0x10057c3f4 v8::internal::Heap::AllocateRawWithRetryOrFail(int, v8::internal::AllocationSpace, v8::internal::AllocationAlignment) [/usr/local/bin/node]
 6: 0x10054e1e4 v8::internal::Factory::NewRawTwoByteString(int, v8::internal::PretenureFlag) [/usr/local/bin/node]
 7: 0x10067fd99 v8::internal::String::SlowFlatten(v8::internal::Handle<v8::internal::ConsString>, v8::internal::PretenureFlag) [/usr/local/bin/node]
 8: 0x1001c587d v8::String::Utf8Length() const [/usr/local/bin/node]
 9: 0x10004e7b6 node::Buffer::(anonymous namespace)::ByteLengthUtf8(v8::FunctionCallbackInfo<v8::Value> const&) [/usr/local/bin/node]
10: 0x2b9f4f0078a1 
Abort trap: 6

具体来说:我注意到的问题有点 类似,但是当我们尝试运行像这样的节点命令时: node --max_old_space_size=4096 node_modules/.bin/react-scripts start (其他地方提出的解决方案),它应该为 Node 分配更多内存,我们遇到了问题.似乎这将为某些函数分配额外的内存(在为特定文件分配更多内存时我也看到过这种方法)但是当你运行像 这样的命令时我不确定如何做到这一点npm run dev 启动你的开发服务器.

Specifically: I've noticed questions that are somewhat similar, but when we try to run Node commands like this one: node --max_old_space_size=4096 node_modules/.bin/react-scripts start (a solution proposed elsewhere), which should allocate more memory to Node, we run into a problem. It seems that this will allocate extra memory to certain functions (and I've also seen this approach when allocating more memory to a specific file) but I'm not certain how to do that when you're running a command like npm run dev to start your development server.

有什么想法吗?

  • @material-ui/core":^4.0.0-alpha.8",
  • @stripe/react-stripe-js":^1.1.2",
  • cors":^2.8.5",
  • firebase":^7.14.4",
  • 下一个":^9.5.2",
  • 反应":^16.8.6",
  • 反应查询":^2.12.1",

推荐答案

运行 npm run dev 只需调用 package.json 文件中的 dev 脚本即可.

Running npm run dev just call the dev script in your package.json file.

这应该是这样的:

"dev": "next",

您可以添加任何您希望发送到节点的标志,例如:

You can can add any flags you wish to send to node, for example:

"dev": "NODE_OPTIONS="--max_old_space_size=4096" next",

这篇关于如何使用 Next.js 为 Javascript 堆分配更多内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆