gpt4 book ai didi

node.js - 使用 Create React App 和 Plotly.js 时出现内存不足错误

转载 作者:行者123 更新时间:2023-12-03 12:18:16 33 4
gpt4 key购买 nike


<--- Last few GCs --->

[972:000001913A837320] 40900 ms: Mark-sweep 2049.2 (2066.3) -> 2047.3 (2059.3) MB, 2062.9 / 0.1 ms (+ 179.6 ms in 113 steps since start of marking, biggest step 8.9 ms, walltime since start of marking 2512 ms) (average mu = 0.153, current mu = 0.107) [972:000001913A837320] 42835 ms: Mark-sweep 2048.8 (2059.3) -> 2047.7 (2057.8) MB, 1845.1 / 0.0
ms (+ 81.8 ms in 23 steps since start of marking, biggest step 9.0 ms, walltime since start of marking 1935 ms) (average mu = 0.084, current mu = 0.004) al

<--- JS stacktrace --->

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

0: ExitFrame [pc: 00007FF68A20B3BD]
Security context: 0x002c4c9808d1 <JSObject>
1: _append [000002A11D9F9439] [D:\ReactProjects\plotlytest\myplotlysite\node_modules\@babel\generator\lib\buffer.js:~99] [pc=0000014BCF9DB744](this=0x03160f6401b1 <Buffer map = 000000A495510339>,0x02ab7a1c78c9 <String[#1]: >,151182,27,0x02ab7a1c01b9 <null>,0x02ab7a1c04b1 <undefined>,0x02ab7a1c06e9 <false>)
2: append [000002A11D9F9391] [D:\ReactPro...

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
1: 00007FF6895F5EBF napi_wrap+114095
2: 00007FF6895A0B46 v8::base::CPU::has_sse+66998
3: 00007FF6895A1946 v8::base::CPU::has_sse+70582
4: 00007FF689DB6E4E v8::Isolate::ReportExternalAllocationLimitReached+94
5: 00007FF689D9EF21 v8::SharedArrayBuffer::Externalize+833
6: 00007FF689C6B18C v8::internal::Heap::EphemeronKeyWriteBarrierFromCode+1436
7: 00007FF689C763C0 v8::internal::Heap::ProtectUnprotectedMemoryChunks+1312
8: 00007FF689C72EE4 v8::internal::Heap::PageFlagsAreConsistent+3204
9: 00007FF689C686E3 v8::internal::Heap::CollectGarbage+1283
10: 00007FF689C66D54 v8::internal::Heap::AddRetainedMap+2452
11: 00007FF689C8809D v8::internal::Factory::NewFillerObject+61
12: 00007FF6899EE06F v8::internal::interpreter::JumpTableTargetOffsets::iterator::operator=+1295
13: 00007FF68A20B3BD v8::internal::SetupIsolateDelegate::SetupHeap+546637
14: 0000014BCF9DB744
npm ERR! code ELIFECYCLE
npm ERR! errno 134
npm ERR! myplotlysite@0.1.0 start: `react-scripts start`
npm ERR! Exit status 134
npm ERR!
npm ERR! Failed at the myplotlysite@0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
以上是我收到的错误。我遵循了一个非常标准的设置,与本网站上列出的相同: https://github.com/plotly/react-plotly.js/blob/master/README.md
我创建了一个 react 应用程序。当我创建一个 react 应用程序并“npm start”本地主机时,它工作得很好。当我执行下一步时会发生此错误:
执行此操作后,“npm install react-plotly.js plotly.js”,本地主机不再工作,并且出现此错误。
我怎样才能解决这个问题?我尝试查看其他有类似错误的帖子,但似乎没有一个答案正常工作。提前致谢。
顺便说一下,我很好奇,为什么这个错误这么多年还存在? plotly 不适合 react 或什么?

最佳答案

在 repo 问题跟踪中报告了一些关于这个确切问题的问题,例如:

  • JavaScript heap out of memory error with the quickstart Plot example .
  • Javascript runs out of memory when making production build

  • 在这些问题中,我们清楚地看到这是一个 NodeJS <= 10 内存分配问题,对此有几种解决方案:
    尝试将您的 NodeJS 版本升级到最新的 12.x 版本
    Node >= 12 会自动增加堆大小,它会起作用。我建议你安装 Node Version Manager (nvm) for Windows这将使您能够快速轻松地安装和切换多个 Node 版本。
    手动增加 max_old_space_size响应脚本
    使用 max_old_space_size 增加堆大小通过将此带有内存大小的选项添加到 package.json脚本:
    "scripts": {
    ...
    "start": "react-scripts --max_old_space_size=4096 start",
    "build": "react-scripts --max_old_space_size=4096 build",
    ...
    }
    使用 Partial bundles

    Partial bundles

    Starting in v1.15.0, plotly.js also ships with several partial bundles:

    Starting in v1.39.0, each plotly.js partial bundle has a corresponding npm package with no dependencies.

    Starting in v1.50.0, the minified version of each partial bundle is also published to npm in a separate "dist min" package.

    plotly.js basic

    The basic partial bundle contains trace modules scatter, bar and pie.


    您可以从 plotly.js-basic-dist 加载库它被编译并在捆绑时消耗更少的内存:
    import React from "react";
    // import Plot from "react-plotly.js";
    import Plotly from "plotly.js-basic-dist";

    import createPlotlyComponent from "react-plotly.js/factory";
    const Plot = createPlotlyComponent(Plotly);

    关于node.js - 使用 Create React App 和 Plotly.js 时出现内存不足错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65866399/

    33 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com