程序问答   发布时间:2022-06-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Azure DevOps React Container Production Build JavaScript heap out of memory 错误大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决Azure DevOps React Container Production Build JavaScript heap out of memory 错误?

开发过程中遇到Azure DevOps React Container Production Build JavaScript heap out of memory 错误的问题如何解决?下面主要结合日常开发的经验,给出你关于Azure DevOps React Container Production Build JavaScript heap out of memory 错误的解决方法建议,希望对你解决Azure DevOps React Container Production Build JavaScript heap out of memory 错误有所启发或帮助;

我正在尝试使用 Azure DevOps 管道构建 react prod docker 容器。升级构建环境和代码后,Pipeline 失败。经过一番研究,我在构建命令中添加了“--node-flags --max-old-space-size=8192”语句。不过没关系。我还尝试了构建的相关节点容器,但没有奏效。

> demo1@7.0.6 build /app
> react-scripts build

CreaTing an optimized production build...

    <--- Last few GCs --->
    
        
        [27:0x7f9033ec22b0]   518219 ms: Scavenge 1985.4 (2066.8) -> 1969.9 (2066.8) MB,3.7 / 0.0 ms  (average mu = 0.190,current mu = 0.078) alLOCATIOn failure 
        [27:0x7f9033ec22b0]   518272 ms: Scavenge 1985.8 (2067.0) -> 1970.4 (2067.0) MB,5.7 / 0.0 ms  (average mu = 0.190,current mu = 0.078) alLOCATIOn failure 
        [27:0x7f9033ec22b0]   520448 ms: Mark-sweep 1986.2 (2067.3) -> 1963.8 (2067.3) MB,2137.2 / 0.0 ms  (average mu = 0.257,current mu = 0.320) alLOCATIOn failure scavenge might not succeed
        
        
        <--- Js stacktrace --->
        
        Fatal error: Ineffective mark-compacts near heap limit AlLOCATIOn Failed - JavaScript heap out of memory
        npm ERR! code EliFECYCLE
        npm ERR! errno 1
        npm ERR! demo1@7.0.6 build: `react-scripts build`
        npm ERR! Exit status 1
        npm ERR! 
        npm ERR! Failed at the demo1@7.0.6 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/2021-06-13T21_04_02_873Z-deBUG.log
        The command '/bin/sh -c npm run-script build --node-flags --max-old-space-size=8192' returned a non-zero code: 1
        ##[error]The command '/bin/sh -c npm run-script build --node-flags --max-old-space-size=8192' returned a non-zero code: 1
        ##[error]The process '/usr/bin/docker' Failed with exit code 1
        Finishing: Docker

Dockerfile:

# stage1 - build react app first 
FROM node:14.16.1-alpine3.13 as build
workdir /app
ENV PATH /app/node_modules/.bin:$PATH
copY ./package.Json /app/
RUN apk --no-cache add g++ gcc libgcc libstdc++ linux-headers make py3-pip git
RUN npm install --quIEt node-gyp -g
RUN npm install
copY . /app
RUN npm run-script build --node-flags --max-old-space-size=8192

我的 package.Json 文件:

{
    "name": "demo1","version": "7.0.6","private": true,"homepage": "","scripts": {
        "start": "react-scripts start -o","build": "react-scripts build","test": "react-scripts test","eject": "react-scripts eject","lint": "eslint src","format": "prettIEr --write \"src/**/*.{Js,CSS,sCSS,HTML}\"","rtl": "webpack"
    },"eslintConfig": {
        "extends": "react-app"
    },"browsersList": {
        "production": [
            ">0.2%","not dead","not op_mini all","IE 11"
        ],"development": [
            "last 1 Chrome version","last 1 firefox version","last 1 safari version","last 1 edge version","IE 11"
        ]
    },"dependencIEs": {
        "@ant-design/charts": "^1.1.1","@ant-design/icons": "^4.6.2","@babel/standalone": "^7.14.4","@date-io/date-fns": "2.6.1","@emotion/react": "^11.4.0","@formatJs/intl-pluralrules": "1.3.5","@fortawesome/Fontawesome-free": "5.13.0","@manaflair/redux-batch": "1.0.0","@material-ui/core": "4.9.14","@material-ui/icons": "4.9.1","@material-ui/lab": "4.0.0-Alpha.53","@material-ui/pickers": "3.2.10","@material-ui/styles": "4.9.14","@phuocng/react-pdf-vIEwer": "^1.7.0","@react-Google-maps/API": "^2.2.0","@reduxJs/toolkit": "1.3.6","@tanem/svg-injector": "8.0.50","antd": "^4.13.0","antd-mask-input": "^0.1.15","apexcharts": "3.19.2","axios": "0.19.2","axios-mock-adapter": "1.18.1","bootstrap": "4.5.0","bulma": "^0.9.2","bulma-Helpers": "^0.4.0","chart.Js": "^3.3.2","classnames": "^2.3.1","clipboard-copy": "3.1.0","cLSX": "1.1.0","convert-units": "^2.3.4","cp-cli": "2.0.0","css-mediaquery": "0.1.2","date-fns": "2.8.1","dentist": "^1.0.3","dom-to-image": "^2.6.0","downshift": "3.4.2","email-valIDator": "^2.0.4","fg-loadCSS": "2.1.0","formik": "2.1.4","frappe-gantt-react": "^0.2.2","fs": "*","HTML-react-parser": "^1.2.5","HTML2canvas": "*","inputmask-core": "^2.2.0","jquery": "^3.6.0","Json2mq": "0.2.0","Jspdf": "^2.3.1","Jspdf-au@R_701_10586@ble": "^3.5.14","Jss-rtl": "^0.3.0","lodash": "4.17.15","material-ui-popup-state": "1.4.1","node-sass": "^4.0.0","object-path": "0.11.4","pdfJs-dist": "^2.7.570","perfect-scrollbar": "1.5.0","primeicons": "^4.1.0","primereact": "^6.2.1","prop-types": "15.7.2","qrcode.react": "^1.0.1","quill": "^1.3.7","rc-year-calendar": "^1.0.2","react": "16.12.0","react-bootstrap": "1.0.1","react-bootstrap-table-next": "4.0.2","react-bootstrap-table2-editor": "^1.4.0","react-bootstrap-table2-filter": "^1.3.3","react-bootstrap-table2-paginator": "2.1.2","react-bootstrap-table2-toolkit": "^2.1.3","react-color": "^2.19.3","react-contexify": "^4.1.1","react-country-region-SELEctor": "^3.1.0","react-data-table-component": "^6.11.7","react-date-picker": "^8.2.0","react-datepicker": "2.16.0","react-dom": "16.12.0","react-draggable": "4.4.2","react-export-excel": "^0.5.3","react-Google-maps": "^9.4.5","react-HelR_600_11845@et": "^6.1.0","react-highlight": "^0.14.0","react-highlight-words": "^0.17.0","react-horizontal-timeline": "^1.5.3","react-inlinesvg": "1.2.0","react-intl": "3.6.2","react-is": "16.13.1","react-jvectormap": "0.0.16","react-loader-spinner": "^4.0.0","react-moment": "^1.1.1","react-pdf": "^5.3.0","react-pdfJs-multi": "^0.5.1","react-perfect-scrollbar": "1.5.8","react-phone-input-2": "^2.14.0","react-portal": "4.2.0","react-qr-reader": "^2.2.1","react-qr-scAnner": "*","react-redux": "7.1.3","react-router-dom": "5.1.2","react-router-last-LOCATIOn": "^2.0.1","react-scripts": "3.2.0","react-SELEct": "3.1.0","react-share": "^4.4.0","react-swipeable-vIEws": "0.13.9","react-Syntax-Highlighter": "12.2.1","react-to-print": "^2.12.6","react-toggle": "^4.1.2","react-Transition-group": "^4.4.2","react-window": "1.8.5","reactJs-pdf-reader": "^1.0.12","reactstrap": "^8.9.0","redux": "4.0.5","redux-devtools-extension": "^2.13.9","redux-logger": "^3.0.6","redux-persist": "6.0.0","redux-promise-mIDdleware": "^6.1.2","redux-saga": "1.1.3","redux-thunk": "^2.3.0","rsuite": "^4.10.2","socicon": "3.0.5","sockJs-clIEnt": "^1.4.0","stompJs": "^2.3.3","styled-components": "^5.3.0","xLSX": "0.13.4","yup": "0.29.0"
    },"devDependencIEs": {
        "@babel/plugin-transform-react-Jsx": "^7.14.3","copyfiles": "2.1.1","node-sass": "4.14.0","prettIEr": "1.19.1","serve": "11.2.0","webpack-cli": "3.3.11","webpack-messages": "2.0.4","webpack-rtl-plugin": "2.0.0"
    }
}

感谢您的帮助!

解决方法

我知道“--max-old-space-size=8192”参数不会传递给构建。所以我决定在 Dockerfile 中添加 ENV,比如“ENV NODE_OPTIONS="--max-old-space-size=8192"”。最后我的 Dockerfile 转换为:

# stage1 - build react app first 
FROM node:14.16.1-alpine3.13 as build
WORKDIR /app
ENV NODE_OPTIONS="--max-old-space-size=8192"
ENV PATH /app/node_modules/.bin:$PATH
COPY ./package.json /app/
RUN apk --no-cache add g++ gcc libgcc libstdc++ linux-headers make py3-pip git
RUN npm install --quiet node-gyp -g
RUN npm install
COPY . /app
RUN npm run-script build

然后问题就解决了。谢谢。

大佬总结

以上是大佬教程为你收集整理的Azure DevOps React Container Production Build JavaScript heap out of memory 错误全部内容,希望文章能够帮你解决Azure DevOps React Container Production Build JavaScript heap out of memory 错误所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。