dify 在本地启动网页时,在运行构建过程中遇到"致命的JavaScript无效大小错误169220804",

gojuced7  于 2个月前  发布在  Java
关注(0)|答案(9)|浏览(88)

自检

  • 仅用于提交错误报告,如果您想提问,请访问 Discussions
  • 我已搜索现有问题 search for existing issues ,包括已关闭的问题。
  • 我确认我使用英语提交此报告(我已阅读并同意 Language Policy )。
  • 请不要修改此模板 :) 并填写所有必需的字段。

Dify版本

0.6.9

云或自托管

自托管(Docker)

重现步骤

✔️ 预期行为

构建成功

❌ 实际行为

致命JavaScript无效大小错误 169220804

jgzswidk

jgzswidk1#

我尝试过18.17.0和18.17.1版本,但同样的问题仍然存在。

oymdgrw7

oymdgrw72#

如果降级Node.js没有解决问题,让我们尝试一些额外的步骤来故障排除并可能解决“致命JavaScript无效大小错误169220804”:

  1. 清除npm缓存:
npm cache clean --force
  1. 删除 node_modulespackage-lock.json:
rm -rf node_modules package-lock.json
  1. 重新安装依赖项:
npm install
  1. 确保Docker正在使用正确的Node.js版本:
    确保您的Dockerfile指定了正确的Node.js版本。例如:
FROM node:18.17.0
  1. 检查依赖项中是否存在任何已知问题:
    有时特定版本的依赖项可能会导致问题。确保所有依赖项都是最新的,并检查您正在使用的版本中是否存在任何已知问题。
  2. 增加Node.js的内存限制:
    有时构建过程可能会因内存限制而失败。您可以尝试增加内存限制:
NODE_OPTIONS="--max-old-space-size=4096" npm run build

如果在执行这些步骤后问题仍然存在,您可能需要查看可能导致问题的特定依赖项或配置。

  • 要继续与 1(https://github.com/langgenius/dify/blob/main/web/package.json) 交谈,请提及 @dosu。*
kiz8lqtg

kiz8lqtg3#

Following the steps above, I have allocated enough memory to the node, and even tried larger allocations, but still cannot solve this issue; could it be some problems with the dependencies such as the version of "next", or maybe there are issues with the webpack configuration?

nfeuvbwi

nfeuvbwi4#

要解决Next.js 14.2.3生产构建过程中出现的"Fatal JavaScript invalid size error 169220804"问题,尽管已经增加了内存限制,请考虑以下步骤:

  1. 检查依赖项:
    确保所有依赖项与Next.js 14.2.3兼容。有时,特定版本的依赖项可能会导致问题。以下是Dify项目中列出的package.json依赖项:
"dependencies": {
  "@babel/runtime": "^7.22.3",
  "@dagrejs/dagre": "^1.1.2",
  "@emoji-mart/data": "^1.1.2",
  "@floating-ui/react": "^0.25.2",
  "@formatjs/intl-localematcher": "^0.5.4",
  "@headlessui/react": "^1.7.13",
  "@heroicons/react": "^2.0.16",
  "@hookform/resolvers": "^3.3.4",
  "@lexical/react": "^0.12.2",
  "@mdx-js/loader": "^2.3.0",
  "@mdx-js/react": "^2.3.0",
  "@monaco-editor/react": "^4.6.0",
  "@next/mdx": "^14.0.4",
  "@sentry/react": "^7.54.0",
  "@sentry/utils": "^7.54.0",
  "@tailwindcss/line-clamp": "^0.4.4",
  "@tailwindcss/typography": "^0.5.9",
  "ahooks": "^3.7.5",
  "classnames": "^2.3.2",
  "copy-to-clipboard": "^3.3.3",
  "crypto-js": "^4.2.0",
  "dayjs": "^1.11.7",
  "echarts": "^5.4.1",
  "echarts-for-react": "^3.0.2",
  "emoji-mart": "^5.5.2",
  "i18next": "^22.4.13",
  "i18next-resources-to-backend": "^1.1.3",
  "immer": "^9.0.19",
  "js-audio-recorder": "^1.0.7",
  "js-cookie": "^3.0.1",
  "katex": "^0.16.10",
  "lamejs": "^1.2.1",
  "lexical": "^0.12.2",
  "lodash-es": "^4.17.21",
  "mermaid": "10.4.0",
  "negotiator": "^0.6.3",
  "next": "^14.0.4",
  "next-nprogress-bar": "^2.3.8",
  "qrcode.react": "^3.1.0",
  "qs": "^6.11.1",
  "rc-textarea": "^1.5.2",
  "react": "~18.2.0",
  "react-18-input-autosize": "^3.0.0",
  "react-dom": "~18.2.0",
  "react-error-boundary": "^4.0.2",
  "react-headless-pagination": "^1.1.4",
  "react-hook-form": "^7.51.4",
  "react-i18next": "^12.2.0",
  "react-infinite-scroll-component": "^6.1.0",
  "react-markdown": "^8.0.6",
  "react-multi-email": "^1.0.14",
  "react-papaparse": "^4.1.0",
  "react-slider": "^2.0.4",
  "react-sortablejs": "^6.1.4",
  "react-syntax-highlighter": "^15.5.0",
  "react-tooltip": "5.8.3",
  "react-window": "^1.8.9",
  "react-window-infinite-loader": "^1.0.9",
  "reactflow": "^11.11.3",
  "recordrtc": "^5.6.2",
  "rehype-katex": "^6.0.2",
  "remark-breaks": "^3.0.2",
  "remark-gfm": "^3.0.1",
  "remark-math": "^5.1.1",
  "scheduler": "^0.23.0",
  "server-only": "^0.0.1",
  "sharp": "^0.33.2",
  "sortablejs": "^1.15.0",
  "swr": "^2.1.0",
  "use-context-selector": "^1.4.1",
  "uuid": "^9.0.1",
  "zod": "^3.23.6",
  "zustand": "^4.5.1"
},
"devDependencies": {
  "@antfu/eslint-config": "^0.36.0",
  "@faker-js/faker": "^7.6.0",
  "@rgrove/parse-xml": "^4.1.0",
  "@types/crypto-js": "^4.1.1",
  "@types/dagre": "^0.7.52",
  "@types/js-cookie": "^3.0.3",
  "@types/lodash-es": "^4.17.7",
  "@types/negotiator": "^0.6.1",
  "@types/node": "18.15.0",
  "@types/qs": "^6.9.7",
  "@types/react": "~18.2.0",
  "@types/react-dom": "~18.2.0",
  "@types/react-slider": "^1.3.1",
  "@types/react-syntax-highlighter": "^15.5.6",
  "@types/react-window": "^1.8.5",
  "@types/react-window-infinite-loader": "^1.0.6",
  "@types/recordrtc": "^5.6.11",
  "@types/sortablejs": "^1.15.1",
  "@types/uuid": "^9.0.8",
  "autoprefixer": "^10.4.14",
  "code-inspector-plugin": "^0.13.0",
  "cross-env": "^7.0.3",
  "eslint": "^8.36.0",
  "eslint-config-next": "^14.0.4",
  "husky": "^8.0.3",
  "lint-staged": "^13.2.2",
  "postcss": "^8.4.31",
  "sass": "^1.61.0",
  "tailwindcss": "^3.3.3",
  "typescript": "4.9.5",
  "uglify-js": "^3.17.4"
}

确保这些依赖项彼此兼容,并与Next.js 14.2.3 1(https://github.com/langgenius/dify/blob/main/sdks/nodejs-client/package.json)2(https://github.com/langgenius/dify/blob/main/web/package.json)兼容。

  1. 自定义Webpack配置:
    检查是否有任何可能影响构建过程的自定义webpack配置或插件。自定义配置有时会导致内存问题。如果您有自定义webpack配置,请尝试简化它们或删除不必要的插件,以查看是否解决了问题。

  2. 环境配置:
    确保环境配置针对大型构建进行了优化。例如,将NEXT_PUBLIC_DEPLOY_ENV设置为PRODUCTION并正确配置NEXT_PUBLIC_API_PREFIXNEXT_PUBLIC_PUBLIC_API_PREFIX可以帮助优化构建过程3(https://github.com/langgenius/dify/blob/main/web/.env.example)4(https://github.com/langgenius/dify/blob/main/web/config/index.ts)。

  • 优化构建过程:
  • 代码拆分:确保您的应用程序使用代码拆分来减小捆绑包的大小。
  • Tree Shaking:确保在构建过程中删除未使用的代码。
  • 分析捆绑包大小:使用工具如webpack-bundle-analyzer来分析捆绑包大小并识别可以优化的大型模块。
  • 使用不同的基础镜像:

如果您正在使用Docker,请尝试使用不同的基础镜像。有时,问题可能源于特定的Node.js版本或所使用的基

vojdkbi0

vojdkbi05#

如何配置本地环境变量local.

ma8fv8wu

ma8fv8wu6#

要为优化Next.js 14.2.3生产构建过程的环境设置配置env.local文件,您应该设置NEXT_PUBLIC_DEPLOY_ENVNEXT_PUBLIC_API_PREFIXNEXT_PUBLIC_PUBLIC_API_PREFIX环境变量。以下是一个示例配置:

NEXT_PUBLIC_DEPLOY_ENV=PRODUCTION
NEXT_PUBLIC_API_PREFIX=http://localhost:5001/console/api
NEXT_PUBLIC_PUBLIC_API_PREFIX=http://localhost:5001/api


此配置确保在构建过程中正确设置`apiPrefix`和`publicApiPrefix`:

if (process.env.NEXT_PUBLIC_API_PREFIX && process.env.NEXT_PUBLIC_PUBLIC_API_PREFIX) {
apiPrefix = process.env.NEXT_PUBLIC_API_PREFIX
publicApiPrefix = process.env.NEXT_PUBLIC_PUBLIC_API_PREFIX
}


此外,您还可以使用其他环境变量(如`DEPLOY_ENV`、`CONSOLE_API_URL`和`APP_API_URL`)动态设置这些环境变量。以下是在Docker环境中配置这些变量的示例:

export NEXT_PUBLIC_DEPLOY_ENV=${DEPLOY_ENV}
export NEXT_PUBLIC_API_PREFIX=${CONSOLE_API_URL}/console/api
export NEXT_PUBLIC_PUBLIC_API_PREFIX=${APP_API_URL}/api


这种方法更加灵活,并确保根据部署上下文([[1]](https://github.com/langgenius/dify/blob/main/web/config/index.ts)[[2]](https://github.com/langgenius/dify/blob/main/web/.env.example)[[3]](https://github.com/langgenius/dify/blob/main/web/docker/entrypoint.sh))正确设置环境变量。

* 要继续与[Dosu](https://dosu.dev)交谈,请提及@dosu。*
vxqlmq5t

vxqlmq5t7#

如何配置本地环境变量local.cp .env.example .env.local。但是我认为你的本地机器可能出了问题。你可以忽略除了这条#4994(评论)之外的机器人的回复。

jdzmm42g

jdzmm42g9#

嘿,@qizhiyuan!我在这里协助你解决bug、回答问题并在等待人类维护者时提供帮助。让我们一起解决这个挑战!

要解决Next.js构建过程中的"Fatal JavaScript invalid size error 169220804"错误,请确保您使用的是兼容的Node.js版本。该项目需要Node.js版本>=18.17.0。尽管您正在使用更高版本的Node.js 20.6.1,但可能存在与此较新版本相关的具体问题。尝试降级到Node.js版本18.17.0以查看是否解决了问题。

以下是使用nvm(Node Version Manager)切换到Node.js版本18.17.0的方法:

  1. 如果尚未安装,请安装nvm:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
  1. 安装Node.js版本18.17.0:
nvm install 18.17.0
  1. 使用Node.js版本18.17.0:
nvm use 18.17.0
  1. 验证Node.js版本:
node -v
  1. 重新运行Next.js构建过程:
npm run build

如果与Node.js版本兼容性有关,这应该有助于解决问题。要继续与Dosu交谈,请提及@dosu。

相关问题