gpt4 book ai didi

reactjs - 在生产模式下 Dockerizing React : FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory

转载 作者:行者123 更新时间:2023-12-03 20:25:23 27 4
gpt4 key购买 nike

我正在尝试 dockerize 一个 React 应用程序。虽然我可以在开发模式下做到,但我不能在生产模式下做到。
我也可以在本地构建它,但是当我尝试 Docker 时出现此错误:

Step 10/14 : RUN npm run build
---> Running in 2c95d18e526c

> x@0.1.0 build /x
> react-scripts build

Creating an optimized production build...
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
1: 0x8fb090 node::Abort() [node]
2: 0x8fb0dc [node]
3: 0xb0322e v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [node]

<--- Last few GCs --->

[25:0x4394f50] 192197 ms: Mark-sweep 1375.9 (1444.4) -> 1366.4 (1444.4) MB, 993.9 / 0.0 ms (average mu = 0.209, current mu = 0.125) allocation failure scavenge might not succeed
[25:0x4394f50] 193285 ms: Mark-sweep 1378.5 (1444.4) -> 1368.9 (1447.9) MB, 959.5 / 0.0 ms (average mu = 0.166, current mu = 0.118) allocation failure scavenge might not succeed


<--- JS stacktrace --->

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

0: ExitFrame [pc: 0x277faa75be1d]
1: StubFrame [pc: 0x277faa7047bb]
2: ConstructFrame [pc: 0x277faa70d145]
Security context: 0x3fdee7f9e6c1 <JSObject>
3: DoJoin(aka DoJoin) [0x3fdee7f85e69] [native array.js:~87] [pc=0x277faab5432d](this=0x25a0974826f1 <undefined>,l=0x0b1a02686109 <JSArray[5]>,m=5,A=0x25a0974828c9 <true>,w=0x0817ee2325c9 <String[1]: />,v=0x25a0974829a1 <false>)
4: Join(aka Join) [0x3fdee7f85eb9] [native...

4: 0xb03464 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [node]
5: 0xef74c2 [node]
6: 0xef75c8 v8::internal::Heap::CheckIneffectiveMarkCompact(unsigned long, double) [node]
7: 0xf036a2 v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [node]
8: 0xf03fd4 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [node]
9: 0xf06c41 v8::internal::Heap::AllocateRawWithRetryOrFail(int, v8::internal::AllocationSpace, v8::internal::AllocationAlignment) [node]
10: 0xed00c4 v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationSpace) [node]
11: 0x117024e v8::internal::Runtime_AllocateInNewSpace(int, v8::internal::Object**, v8::internal::Isolate*) [node]
12: 0x277faa75be1d
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! x@0.1.0 build: `react-scripts build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the x@0.1.0 build 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! /root/.npm/_logs/2020-07-01T08_22_44_303Z-debug.log
The command '/bin/sh -c npm run build' returned a non-zero code: 1

我的 Dockerfile 是这样的:
FROM node:10 as build

COPY ./x /x
COPY ./y /y

WORKDIR /y
RUN npm install
RUN npm run build

WORKDIR ../
WORKDIR /x

RUN npm install


#ENV NODE_OPTIONS=--max-old-space-size=8192

RUN npm run build

# production environment
FROM nginx:stable-alpine
COPY --from=build /app/build /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
X 依赖于 Y ,因为我演示了 package.jsonX :
"dependencies": {
"someName": "file:../y",
}
我尝试了很多方法来解决这个问题:
  • 升级或降级 Dockerfile 中的节点
  • 增加应用程序的堆大小(我不确定我是否可以正确完成)

  • 预先感谢您的回答!

    最佳答案

    NODE_OPTIONS 解决方案对我不起作用,我使用的是 Node v14 和 React Scripts v4。
    来自 GitHub 的这个解决方案终于有所帮助 - https://github.com/wojtekmaj/react-pdf/issues/496#issuecomment-566200248

    GENERATE_SOURCEMAP=false
    在构建命令之前添加到我的 Dockerfile 中。
    enter image description here

    关于reactjs - 在生产模式下 Dockerizing React : FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62663167/

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