如何解决在 cloudflare 页面中构建 React 应用程序时出现的错误?

问题描述 投票:0回答:1

当我收到此消息时,我该如何解决它?或者我可以部署构建文件吗?它可以通过带有最新更新的 vscode 在我的 PC 上正常构建,但不会为 Cloudflare 页面构建!

当前 NodeJS 版本 20.16.0

23:36:16.171     * branch              6ff0a04dcfdd07f617761ddab8b19929bbd3e044 -> FETCH_HEAD
23:36:16.172    
23:36:18.156    HEAD is now at 6ff0a04d reset
23:36:18.156    
23:36:18.251    
23:36:18.252    Using v2 root directory strategy
23:36:18.332    Success: Finished cloning repository files
23:36:22.012    Checking for configuration in a wrangler.toml configuration file (BETA)
23:36:22.013    
23:36:22.117    No wrangler.toml file found. Continuing.
23:36:24.103    Detected the following tools from environment: [email protected], [email protected]
23:36:24.104    Installing nodejs 20.16.0
23:36:24.549    Trying to update node-build... ok
23:36:24.654    To follow progress, use 'tail -f /tmp/node-build.20240913043624.628.log' or pass --verbose
23:36:24.764    Downloading node-v20.16.0-linux-x64.tar.gz...
23:36:24.884    -> https://nodejs.org/dist/v20.16.0/node-v20.16.0-linux-x64.tar.gz
23:36:26.484    Installing node-v20.16.0-linux-x64...
23:36:26.876    Installed node-v20.16.0-linux-x64 to /opt/buildhome/.asdf/installs/nodejs/20.16.0
23:36:26.877    
23:36:28.140    Installing project dependencies: npm install --progress=false
23:36:30.644    npm error code ERESOLVE
23:36:30.644    npm error ERESOLVE unable to resolve dependency tree
23:36:30.644    npm error
23:36:30.644    npm error While resolving: [email protected]
23:36:30.644    npm error Found: [email protected]
23:36:30.644    npm error node_modules/react
23:36:30.644    npm error   react@"^18.3.1" from the root project
23:36:30.644    npm error
23:36:30.645    npm error Could not resolve dependency:
23:36:30.645    npm error peer react@"16.x || 17.x" from [email protected]
23:36:30.645    npm error node_modules/react-image-lightbox
23:36:30.645    npm error   react-image-lightbox@"^5.1.4" from the root project
23:36:30.645    npm error
23:36:30.645    npm error Fix the upstream dependency conflict, or retry
23:36:30.645    npm error this command with --force or --legacy-peer-deps
23:36:30.645    npm error to accept an incorrect (and potentially broken) dependency resolution.
23:36:30.645    npm error
23:36:30.645    npm error
23:36:30.645    npm error For a full report see:
23:36:30.645    npm error /opt/buildhome/.npm/_logs/2024-09-13T04_36_28_512Z-eresolve-report.txt
23:36:30.646    npm error A complete log of this run can be found in: /opt/buildhome/.npm/_logs/2024-09-13T04_36_28_512Z-debug-0.log
23:36:30.657    Error: Exit with error code: 1
23:36:30.657        at ChildProcess.<anonymous> (/snapshot/dist/run-build.js)
23:36:30.657        at Object.onceWrapper (node:events:652:26)
23:36:30.657        at ChildProcess.emit (node:events:537:28)
23:36:30.658        at ChildProcess._handle.onexit (node:internal/child_process:291:12)
23:36:30.668    Failed: build command exited with code: 1
23:36:31.690    Failed: error occurred while running build command

当我在 Cloudflare 页面中构建时,我收到上述日志。

我正在使用以下构建命令:

npm run build
Build output directory:
/build
Root directory:
/frontend
Build comments on pull requests:
Enabled
reactjs npm cloudflare
1个回答
0
投票

问题与v1到v2有关。这会导致使用 npm 默认 v9.6.7,我猜它与节点 v20.16 不兼容 https://developers.cloudflare.com/pages/configuration/build-image/#v1-to-v2-migration

© www.soinside.com 2019 - 2024. All rights reserved.