【问题标题】:NextJS - FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memoryNextJS - 致命错误:堆限制附近的无效标记压缩分配失败 - JavaScript 堆内存不足
【发布时间】:2023-02-20 00:07:57
【问题描述】:

我有 NextJS typescript 应用程序,有 30 页和一些依赖项。我正在尝试在具有 512MB 内存的免费实例上构建它,但构建有时甚至无法完成检查类型有效性的步骤。 我收到错误FATAL ERROR: Ineffective mark-compacts near heap limit 分配失败 - JavaScript 堆内存不足

这是 package.json

{
      "name": "app",
      "scripts": {
        "dev": "next dev",
        "build": "NODE_OPTIONS=\" --max-old-space-size=512\"  next build",
        "prestart": "npm run build",
        "start": "NODE_OPTIONS=\"--max-old-space-size=512\" next start","test": "start-server-and-test dev 3000 cypress:open",
        "type:check": "yarn tsc --project tsconfig.json --pretty --noEmit",
        "prepare": "husky install"
      },
      "dependencies": {
        "@fortawesome/fontawesome-svg-core": "^1.3.0",
        "@fortawesome/free-regular-svg-icons": "^6.0.0",
        "@fortawesome/free-solid-svg-icons": "^6.0.0",
        "@fortawesome/react-fontawesome": "^0.1.17",
        "@lexical/react": "^0.7.1",
        "@reduxjs/toolkit": "^1.7.2",
        "@tangdw/react-viewer": "^3.2.7",
        "antd": "^4.18.8",
        "antd-dayjs-webpack-plugin": "^1.0.6",
        "autoprefixer": "^10.4.7",
        "bootstrap": "5.1.3",
        "country-list": "^2.2.0",
        "draft-js": "^0.11.7",
        "draftjs-to-html": "^0.9.1",
        "formik": "^2.2.9",
        "formik-antd": "^2.0.4",
        "html-to-draftjs": "^1.5.0",
        "jsonwebtoken": "^8.5.1",
        "jwt-decode": "^3.1.2",
        "lodash": "^4.17.21",
        "moment": "^2.29.1",
        "next": "12.0.10",
        "next-pwa": "^5.6.0",
        "nprogress": "^0.2.0",
        "postcss": "^8.4.14",
        "query-string": "^7.1.1",
        "react": "17.0.2",
        "react-dom": "17.0.2",
        "react-draft-wysiwyg": "^1.15.0",
        "react-feather": "^2.0.10",
        "react-icons": "^4.3.1",
        "react-multi-carousel": "^2.8.0",
        "react-redux": "^7.2.6",
        "react-share": "^4.4.1",
        "react-show-more-text": "^1.5.2",
        "react-slick": "^0.29.0",
        "react-typical": "^0.1.3",
        "react-viewer": "^3.2.2",
        "tailwindcss": "^3.0.24",
        "yup": "^0.32.11"
      },
      "devDependencies": {
        "@types/node": "17.0.15",
        "@types/react": "17.0.39",
        "@types/react-show-more-text": "^1.4.2",
        "@typescript-eslint/eslint-plugin": "^5.11.0",
        "@typescript-eslint/parser": "^5.11.0",
        "@types/jsonwebtoken": "^8.5.8",
        "@types/nprogress": "^0.2.0",
        "@types/react-typical": "^0.1.0",
        "cypress": "^9.5.1",
        "eslint": "8.8.0",
        "eslint-config-next": "12.0.10",
        "eslint-config-prettier": "^8.3.0",
        "eslint-plugin-jsx-a11y": "^6.5.1",
        "eslint-plugin-prettier": "^4.0.0",
        "eslint-plugin-react": "^7.28.0",
        "eslint-plugin-react-hooks": "^4.3.0",
        "husky": ">=6",
        "lint-staged": ">=10",
        "miragejs": "^0.1.43",
        "prettier": "2.5.1",
        "start-server-and-test": "^1.14.0",
        "typescript": "4.5.5"
      },
    }

有办法处理吗?

【问题讨论】:

  • 我不确定设置内存限制是个好主意,因为即使内存有限 - 操作系统也可能使用 paging 机制。也许你应该试试不带 --max-old-space-size 标志?

标签: javascript typescript next.js


【解决方案1】:

Another option is make the build locally and upload the build files manually to the server.

I used to do this on my server.

  • I am using the api functions, they need to be deployed as serverless functions
猜你喜欢
  • 2021-11-08
  • 1970-01-01
  • 2020-05-29
  • 2020-09-11
  • 2020-08-05
  • 2019-07-06
  • 2020-04-17
  • 2019-02-11
  • 2019-07-15
相关资源
最近更新 更多