如何修复“致命错误:接近堆限制的无效标记压缩分配失败 - JavaScript 堆内存不足”错误

2024-02-27

我正在尝试将reactjs应用程序部署到heroku。编译资产时,构建失败并产生以下错误:

-----> Ruby app detected
-----> Compiling Ruby/Rails
-----> Using Ruby version: ruby-2.5.1
-----> Installing dependencies using bundler 1.15.2
       Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4 --deployment
       Warning: the running version of Bundler (1.15.2) is older than the version that created the lockfile (1.16.3). We suggest you upgrade to the latest version of Bundler by running `gem install bundler`.
       Fetching gem metadata from https://rubygems.org/............
       Fetching version metadata from https://rubygems.org/..
       Fetching dependency metadata from https://rubygems.org/.
       Using rake 12.3.1
       Using concurrent-ruby 1.1.3
       Using minitest 5.11.3
       Using thread_safe 0.3.6
       Using builder 3.2.3
       Using erubi 1.7.1
       Using mini_portile2 2.3.0
       Using crass 1.0.4
       Using rack 2.0.6
       Using nio4r 2.3.1
       Using websocket-extensions 0.1.3
       Using mini_mime 1.0.1
       Using jsonapi-renderer 0.2.0
       Using arel 9.0.0
       Using mimemagic 0.3.2
       Using public_suffix 3.0.3
       Using airbrake-ruby 2.12.0
       Using execjs 2.7.0
       Using bcrypt 3.1.12
       Using popper_js 1.14.5
       Using rb-fsevent 0.10.3
       Using ffi 1.9.25
       Using bundler 1.15.2
       Using regexp_parser 1.3.0
       Using mime-types-data 3.2018.0812
       Using chartkick 3.0.1
       Using highline 2.0.0
       Using connection_pool 2.2.2
       Using orm_adapter 0.5.0
       Using method_source 0.9.2
       Using thor 0.19.4
       Using multipart-post 2.0.0
       Using geokit 1.13.1
       Using temple 0.8.0
       Using tilt 2.0.9
       Using hashie 3.5.7
       Using json 2.1.0
       Using mini_magick 4.9.2
       Using multi_json 1.13.1
       Using newrelic_rpm 5.5.0.348
       Using one_signal 1.2.0
       Using xml-simple 1.1.5
       Using pg 0.21.0
       Using puma 3.12.0
       Using rack-timeout 0.5.1
       Using redis 4.0.3
       Using secure_headers 6.0.0
       Using swagger-ui_rails 0.1.7
       Using i18n 1.1.1
       Using nokogiri 1.8.5
       Using tzinfo 1.2.5
       Using websocket-driver 0.7.0
       Using mail 2.7.1
       Using marcel 0.3.3
       Using addressable 2.5.2
       Using rack-test 1.1.0
       Using warden 1.2.8
       Using sprockets 3.7.2
       Using request_store 1.4.1
       Using rack-protection 2.0.4
       Using rack-proxy 0.6.5
       Using autoprefixer-rails 9.4.2
       Using uglifier 4.1.20
       Using airbrake 7.4.0
       Using rb-inotify 0.9.10
       Using mime-types 3.2.2
       Using commander 4.4.7
       Using net-http-persistent 3.0.0
       Using faraday 0.15.4
       Using hashie-forbidden_attributes 0.1.1
       Using omniauth 1.8.1
       Using haml 5.0.4
       Using slim 4.0.1
       Using paypal-sdk-core 0.3.4
       Using faker 1.9.1 from https://github.com/stympy/faker.git (at master@aca03be)
       Using money 6.13.1
       Using loofah 2.2.3
       Using xpath 3.2.0
       Using activesupport 5.2.0
       Using sidekiq 5.2.3
       Using sass-listen 4.0.0
       Using houston 2.4.0
       Using stripe 4.2.0
       Using paypal-sdk-adaptivepayments 1.117.1
       Using monetize 1.9.0
       Using rails-html-sanitizer 1.0.4
       Using capybara 3.12.0
       Using rails-dom-testing 2.0.3
       Using globalid 0.4.1
       Using activemodel 5.2.0
       Using case_transform 0.2
       Using decent_exposure 3.0.0
       Using factory_bot 4.11.1
       Using fast_jsonapi 1.5
       Using groupdate 4.1.0
       Using pundit 2.0.0
       Using sass 3.7.2
       Using actionview 5.2.0
       Using activerecord 5.2.0
       Using carrierwave 1.2.3
       Using activejob 5.2.0
       Using actionpack 5.2.0
       Using bootstrap 4.1.3
       Using actioncable 5.2.0
       Using actionmailer 5.2.0
       Using active_model_serializers 0.10.8
       Using activestorage 5.2.0
       Using railties 5.2.0
       Using sprockets-rails 3.2.1
       Using simple_form 4.1.0
       Using responders 2.4.0
       Using factory_bot_rails 4.11.1
       Using font-awesome-rails 4.7.0.4
       Using highcharts-rails 6.0.3
       Using jquery-rails 4.3.3
       Using lograge 0.10.0
       Using money-rails 1.13.0
       Using slim-rails 3.2.0
       Using webpacker 3.5.5
       Using rails 5.2.0
       Using sass-rails 5.0.7
       Using geokit-rails 2.3.1
       Using swagger-docs 0.2.9
       Using devise 4.5.0
       Using devise_token_auth 1.0.0
       Bundle complete! 68 Gemfile dependencies, 125 gems now installed.
       Gems in the groups development and test were not installed.
       Bundled gems are installed into ./vendor/bundle.
       Bundle completed (5.09s)
       Cleaning up the bundler cache.
       Warning: the running version of Bundler (1.15.2) is older than the version that created the lockfile (1.16.3). We suggest you upgrade to the latest version of Bundler by running `gem install bundler`.
       The latest bundler is 2.0.1, but you are currently running 1.15.2.
       To update, run `gem install bundler`
-----> Installing node-v10.14.1-linux-x64
-----> Installing yarn-v1.12.3
-----> Detecting rake tasks
-----> Preparing app for Rails asset pipeline
       Running: rake assets:precompile
       yarn install v1.12.3
       warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.
       [1/5] Validating package.json...
       [2/5] Resolving packages...
       [3/5] Fetching packages...
       info [email protected] /cdn-cgi/l/email-protection: The platform "linux" is incompatible with this module.
       info "[email protected] /cdn-cgi/l/email-protection" is an optional dependency and failed compatibility check. Excluding it from installation.
       [4/5] Linking dependencies...
       warning "@rails/webpacker > [email protected] /cdn-cgi/l/email-protection" has unmet peer dependency "caniuse-lite@^1.0.30000697".
       warning " > [email protected] /cdn-cgi/l/email-protection" has incorrect peer dependency "react@^15.4.2".
       warning " > react-bootstrap-[email protected] /cdn-cgi/l/email-protection" has unmet peer dependency "classnames@^2.2.5".
       warning " > [email protected] /cdn-cgi/l/email-protection" has incorrect peer dependency "react@^15.0.1".
       warning " > [email protected] /cdn-cgi/l/email-protection" has unmet peer dependency "immutable@^3.8.1 || ^4.0.0-rc.1".
       warning "eslint-config-airbnb > [email protected] /cdn-cgi/l/email-protection" has incorrect peer dependency "eslint-plugin-import@^2.7.0".
       warning " > [email protected] /cdn-cgi/l/email-protection" has unmet peer dependency "webpack@^2.2.0 || ^3.0.0".
       warning "webpack-dev-server > [email protected] /cdn-cgi/l/email-protection" has unmet peer dependency "webpack@^1.0.0 || ^2.0.0 || ^3.0.0".
       [5/5] Building fresh packages...
       $ cd client && yarn
       yarn install v1.12.3
       warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.
       [1/5] Validating package.json...
       [2/5] Resolving packages...
       [3/5] Fetching packages...
       info [email protected] /cdn-cgi/l/email-protection: The platform "linux" is incompatible with this module.
       info "[email protected] /cdn-cgi/l/email-protection" is an optional dependency and failed compatibility check. Excluding it from installation.
       [4/5] Linking dependencies...
       warning " > [email protected] /cdn-cgi/l/email-protection" has unmet peer dependency "webpack@2 || 3".
       warning " > [email protected] /cdn-cgi/l/email-protection" has incorrect peer dependency "react@^0.14.9 || ^15.0.0".
       warning " > [email protected] /cdn-cgi/l/email-protection" has incorrect peer dependency "react@^15".
       warning " > [email protected] /cdn-cgi/l/email-protection" has incorrect peer dependency "react@^15".
       warning " > [email protected] /cdn-cgi/l/email-protection" has incorrect peer dependency "[email protected] /cdn-cgi/l/email-protection || 0.14.x || ^15.0.0-0 || 15.x".
       warning " > [email protected] /cdn-cgi/l/email-protection" has unmet peer dependency "webpack@>=1.11.0".
       warning " > [email protected] /cdn-cgi/l/email-protection" has unmet peer dependency "webpack@1 || ^2 || ^2.1.0-beta || ^2.2.0-rc || ^3".
       warning "image-webpack-loader > [email protected] /cdn-cgi/l/email-protection" has unmet peer dependency "webpack@^2.0.0 || ^3.0.0 || ^4.0.0".
       warning " > [email protected] /cdn-cgi/l/email-protection" has incorrect peer dependency "react@^15.6.1".
       [5/5] Building fresh packages...
       Done in 31.85s.
       Done in 76.09s.
       Webpacker is installed ???? ????
       Using /tmp/build_8f521e11fc612876bcd3c01cd8da6bdd/config/webpacker.yml file for setting up webpack paths
       Compiling…
       Compilation failed:
       FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
        1: 0x8dbaa0 node::Abort() [node]
        2: 0x8dbaec  [node]
        3: 0xad83de v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [node]
        4: 0xad8614 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [node]
        5: 0xec5c42  [node]
        6: 0xec5d48 v8::internal::Heap::CheckIneffectiveMarkCompact(unsigned long, double) [node]
        7: 0xed1e22 v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [node]
        8: 0xed2754 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [node]
        9: 0xed53c1 v8::internal::Heap::AllocateRawWithRetryOrFail(int, v8::internal::AllocationSpace, v8::internal::AllocationAlignment) [node]
       10: 0xe9e844 v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationSpace) [node]
       11: 0x113dfae v8::internal::Runtime_AllocateInNewSpace(int, v8::internal::Object**, v8::internal::Isolate*) [node]
       12: 0x2daefc5be1d 


       <--- Last few GCs --->

       [587:0x2713f20]  1469419 ms: Mark-sweep 1362.0 (1417.7) -> 1361.9 (1418.2) MB, 1183.8 / 0.0 ms  (average mu = 0.099, current mu = 0.004) allocation failure scavenge might not succeed
       [587:0x2713f20]  1470575 ms: Mark-sweep 1363.1 (1418.7) -> 1362.9 (1419.7) MB, 1151.7 / 0.0 ms  (average mu = 0.053, current mu = 0.004) allocation failure scavenge might not succeed


       <--- JS stacktrace --->

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

           0: ExitFrame [pc: 0x2daefc5be1d]
       Security context: 0x395bbaa1e6e1 <JSObject>
           1: addMappingWithCode [0x1a4bb3f1a89] [/tmp/build_8f521e11fc612876bcd3c01cd8da6bdd/node_modules/webpack-sources/node_modules/source-map/lib/source-node.js:~150] [pc=0x2daf487dfd2](this=0x08663a09ad49 <JSGlobal Object>,mapping=0x2969e26a1e61 <Object map = 0x1067d74ad2e1>,code=0x3e38d99f4479 <String[6]: break >)
           2: /* anonymous */ [0x1a4bb3dcc79] [/tmp/...


 !
 !     Precompiling assets failed.
 !
 !     Push rejected, failed to compile Ruby app.
 !     Push failed

我尝试过各种方法package.json file:

"scripts" : {
   "start": "cross-env NODE_OPTIONS=--max_old_space_size=5120 webpack"
}

"scripts" : {
  "webpacker": "node --max-old-space-size=4096 node_modules/.bin/react-scripts start"
}

"scripts" : {
  "start": "node --max-old-space-size=6144 client/app/app.js"
}

我研究并发现了各种 github 和 stackoverflow 线程,但它们似乎没有解决我的问题。

  • https://github.com/npm/npm/issues/12238 https://github.com/npm/npm/issues/12238
  • 增加 create-react-app 项目中的 JavaScript 堆大小 https://stackoverflow.com/questions/44046366/increase-javascript-heap-size-in-create-react-app-project

这是我的package.json file:

{
  "name": "safe_deliver",
  "private": true,
  "engines": {
    "node": ">=6.0.0",
    "yarn": ">=0.25.2"
  },
  "scripts": {
    "postinstall": "cd client && yarn",
    "pre-commit": "cd client && npm run lint:staged",
    "start": "cross-env NODE_OPTIONS=--max-old-space-size=6144 bin/webpack"
  },
  "dependencies": {
    "@fortawesome/fontawesome": "^1.1.8",
    "@fortawesome/fontawesome-free": "^5.3.1",
    "@fortawesome/fontawesome-free-brands": "^5.0.13",
    "@fortawesome/fontawesome-free-regular": "^5.0.13",
    "@fortawesome/fontawesome-free-solid": "^5.0.13",
    "@fortawesome/fontawesome-svg-core": "^1.2.4",
    "@fortawesome/free-solid-svg-icons": "^5.3.1",
    "@fortawesome/react-fontawesome": "^0.1.3",
    "@rails/webpacker": "^3.3.1",
    "babel-plugin-emotion": "^9.2.6",
    "babel-preset-react": "^6.24.1",
    "babel-preset-stage-0": "^6.24.1",
    "bootstrap": "4.0.0",
    "chart.js": "^2.7.3",
    "chartkick": "^3.0.1",
    "emotion": "^9.2.6",
    "google-maps-react": "^2.0.2",
    "jquery": "^3.2.1",
    "jquery-ujs": "^1.2.2",
    "leaflet": "^1.3.1",
    "normalize.css": "^8.0.1",
    "popper.js": "^1.12.9",
    "prop-types": "^15.6.1",
    "rc-time-picker": "^3.6.2",
    "react": "^16.4.1",
    "react-addons-css-transition-group": "^15.6.2",
    "react-animate-height": "^2.0.5",
    "react-bootstrap-table-next": "^1.4.0",
    "react-calendar": "^2.16.0",
    "react-datepicker": "^2.3.0",
    "react-dom": "^16.4.1",
    "react-emotion": "^9.2.6",
    "react-fontawesome": "^1.6.1",
    "react-geocode": "^0.1.2",
    "react-https-redirect": "^1.0.11",
    "react-input-mask": "^2.0.4",
    "react-progressbar": "^15.4.1",
    "react-star-rating-component": "^1.4.1",
    "react-stripe-elements": "^2.0.1",
    "reactjs-popup": "^1.3.2",
    "redux-immutable": "^4.0.0",
    "reset-css": "^4.0.1",
    "seamless-immutable": "^7.1.4",
    "styled-components": "^3.4.2"
  },
  "devDependencies": {
    "eslint": "3.19.0",
    "eslint-config-airbnb": "15.0.1",
    "eslint-plugin-import": "2.2.0",
    "eslint-plugin-jsx-a11y": "5.0.3",
    "eslint-plugin-react": "7.0.1",
    "pre-commit": "1.2.2",
    "webpack-dev-server": "^2.7.1"
  }
}

我希望这个错误消失并部署应用程序。现在它抛出 javascript 堆内存不足错误。


该问题与项目中的大文件有关。

我正在使用 create-react-app,并且收到了该错误,经过一些搜索后,似乎一个解决方案是这样的。

Put in .env file:

GENERATE_SOURCEMAP=false
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何修复“致命错误:接近堆限制的无效标记压缩分配失败 - JavaScript 堆内存不足”错误 的相关文章

  • React Native:加载图像后应用程序性能不佳

    加载图像似乎没有问题 但是加载完毕后就出现问题了 在我的应用程序中 我在整个游戏中一张一张地加载卡片图像 一旦我加载了 40 张卡片图像 整个应用程序就会变得很慢 它总是发生在第 40 个图像处 当我在第 40 个图像之后继续加载更多卡片图
  • Cloudfoundry:如何组合两个运行时

    cloundfoundry 有没有办法结合两个运行时环境 我正在将 NodeJS 应用程序部署到 IBM Bluemix 现在 我还希望能够执行独立的 jar 文件 但应用程序失败 APP 0 bin sh 1 java not found
  • 使用 Flask/WTForms 和 React 进行 CSRF 保护

    有没有人成功地为使用 React 作为受控组件 提交到 Flask 后端 最好使用 WTForms 的表单实现了 CSRF 保护 我看过很多部分答案 其中一个是关于 Django 的 但找不到任何关于 Flask 的明确答案 我的大问题似乎
  • 在node.js中生成密码重置令牌

    如何在 node js 中生成可在 url 中使用的密码重置令牌 我只需要生成令牌的方法 user reset password token user reset password expire expire date 编辑 这是解决方案
  • NodeJs 永远无法在 ubuntu 服务器中工作

    我安装了forever https www npmjs org package forever作为超级用户在我的 ubuntu 服务器中全局使用 npm 模块 但我无法使用它启动我的nodeJs 应用程序 我在终端中输入 永远 但似乎没有执
  • 如何在node.js中的一定时间后强制解决承诺? [复制]

    这个问题在这里已经有答案了 我正在尝试从其 url 下载大量图像 然后在 Node js 中创建一个 PDF 文件 我正在使用图片下载器 https www npmjs com package image downloader模块下载承诺链
  • React Context 的范围是什么?

    我不清楚在哪里Context可以在 React 应用程序中创建 我可以在组件树中的任何位置创建上下文吗 如果可以 该上下文的范围是否仅限于创建它的子级 或者 Context 本质上是全局的 我可以在文档中的哪里找到这个 案例 我在页面上多次
  • 带 Rails 6/Webpack 的 Gmap

    我正在尝试让以前与早期版本的 Rails 一起使用的 Google 地图设置使用 Rails 6 显示 显然 Rails 6 现在使用 webpack 来处理 javascript 资源 并且我无法让我的应用程序识别用于识别的 Gmaps
  • React onSubmit e.preventDefault() 有时不起作用 + Axios

    现在我在 React 中面临这个奇怪的问题 其中带有 e preventDefault 的 onSubmit 函数有时会避免刷新页面 有时则不会 我创建了两个挂钩来跟踪上传的文件及其进度条 const uploadedFiles setUp
  • 打字稿:“找不到模块”且输入有效

    我刚刚使用 typescript 启动了一个新的 Nodejs 项目 我安装了打字 https github com typings typings https github com typings typings 并使用它来安装 Node
  • Node + Express 会话过期?

    我有一个 Express 应用程序 并且有一个登录表单 我需要持续 1 个月的会话 我是否将 maxAge 设置为一个月 以毫秒为单位 我让两台计算机保持打开状态并登录了 24 小时 当我回来时 两台计算机都已注销 我该如何解决这个问题 实
  • ReferenceError:找不到变量:需要

    我在加载时遇到问题node modules到我的网页之一 我已经安装了 npm node js 并且我想使用require 函数在我的网站上初始化 Firebase 我不知道为什么 但它抛出引用错误 ReferenceError 找不到变量
  • HTMLImageElement 作为 React Child 无效

    我正在尝试异步加载图像 并且仅在加载图像后才将其显示在 React 应用程序中 componentDidMount const img new Image img onload gt this setState originalImage
  • ant-d upload中如何为removeFile添加PopConfirm一个图片文件

    我正在使用 Ant d Upload 通过本地系统上传文件 然后单击文件预览图像上的删除图标 图像文件将被删除 我想添加一个弹出确认 所以我尝试在 onRemovefunction 中添加确认作为承诺但它不起作用 它在浏览器中显示警报 on
  • 将 jquery-mobile 与 Webpack 结合使用

    我正在尝试使用 webpack 加载 jquery mobile 但到目前为止还没有运气 我知道 jquery mobile 依赖于 jquery ui 而 jquery ui 又依赖于 jquery 如何在 Webpack 中设置这样的场
  • 何时不使用承诺[关闭]

    Closed 这个问题是基于意见的 help closed questions 目前不接受答案 在阅读了数十篇关于 es6 Promise 有多伟大以及为什么我们应该实现它们的文章之后 我有这样的感觉 ALL我的 不平凡的 JavaScri
  • 在vscode中使用reactjs报错

    在 Visual Studio 代码中使用 jsx 语法 Visual Studio代码报错 请帮我 谢谢 符号 例如 而不是这样做 return lt button className square gt TODO lt button g
  • Flux + React.js - 操作中的回调是好还是坏?

    让我解释一下我最近遇到的问题 我有 React js Flux 驱动的应用程序 有一个列表显示文章数量 注意 应用程序中有多个不同的列表 和文章详情查看在里面 但每个列表只有一个 API 端点 它返回文章数组 为了显示我需要的详细信息fin
  • 如何获取使用 .map 渲染的第一个元素的 ref?

    我需要在几行中显示视频 卡片 的缩略图 并重点关注第一个缩略图 我使用嵌套地图进行了显示 该代码基本上迭代视频数组并返回多行视频 我们如何关注第一个渲染的元素 我认为我们需要获得第一个要聚焦的元素的引用 但是我们如何在这里设置 ref 并在
  • 尝试将 Firebase 版本回滚到 2.X

    我最近更新到了新的 Firebase 3 但不幸的是 据我所知 它目前不支持 Geofire 查询 这对我的应用程序很重要 我已经将应用程序中的其他所有内容都转为使用 Firebase 2 但是当我尝试时要将我的应用程序部署到 fireba

随机推荐