chatgpt-demo
chatgpt-demo copied to clipboard
Support for Cloudflare.
Clear and concise description of the problem
Due to frequent blocking when deploying to Vercel, Cloudflare is also a good solution. I hope to have
Suggested solution
https://docs.astro.build/en/guides/integrations-guide/cloudflare/
https://docs.astro.build/zh-cn/guides/deploy/cloudflare/
Currently, I followed the above solution to migrate ddiu8081/chatgpt-demo from "@astrojs/vercel": "^3.1.3" to "@astrojs/cloudflare": "^6.1.3".
When deploying with Cloudflare, set NODE_VERSION to 19.7.0.
The deployment log is as follows:
11:50:41.062 |
-- | --
11:50:41.122 | HEAD is now at 0533b2d ci: cloudflare
11:50:41.123 |
11:50:41.267 |
11:50:41.294 | Success: Finished cloning repository files
11:50:42.101 | Installing dependencies
11:50:42.113 | Python version set to 2.7
11:50:45.794 | Downloading and installing node v19.7.0...
11:50:46.250 | Downloading https://nodejs.org/dist/v19.7.0/node-v19.7.0-linux-x64.tar.xz...
11:50:46.698 | Computing checksum with sha256sum
11:50:46.840 | Checksums matched!
11:50:51.271 | node: /lib/x86_64-linux-gnu/libm.so.6: version `GLIBC_2.27' not found (required by node)
11:50:51.272 | node: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.25' not found (required by node)
11:50:51.272 | node: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.28' not found (required by node)
11:50:51.327 | nvm is not compatible with the npm config "prefix" option: currently set to ""
11:50:51.329 | Run `npm config delete prefix` or `nvm use --delete-prefix v19.7.0` to unset it.
11:50:51.330 | Failed to install node version '19.7.0'
11:50:51.334 | Failed: build command exited with code: 1
11:50:52.391 | Failed: an internal error occurred
Alternative
No response
Additional context
No response
Validations
- [X] Follow our Code of Conduct
- [X] Read the Contributing Guide.
- [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
Sounds good. PR welcome.
@h7ml cloudflare unsupport node 18+, how do you fix this?
16:34:41.770 | Cloning repository... -- | -- 16:34:42.611 | From https://github.com/clearcodecn/chatgpt-demo 16:34:42.612 | * branch f70b3296d66a36b58a21856fc88bb3f1882f3e2f -> FETCH_HEAD 16:34:42.612 | 16:34:42.663 | HEAD is now at f70b329 feat: change logo 16:34:42.664 | 16:34:42.803 | 16:34:42.829 | Success: Finished cloning repository files 16:34:43.561 | Installing dependencies 16:34:43.572 | Python version set to 2.7 16:34:46.879 | Downloading and installing node v18.14.2... 16:34:47.301 | Downloading https://nodejs.org/dist/v18.14.2/node-v18.14.2-linux-x64.tar.xz... 16:34:47.753 | Computing checksum with sha256sum 16:34:47.889 | Checksums matched! 16:34:52.080 | node: /lib/x86_64-linux-gnu/libm.so.6: version `GLIBC_2.27' not found (required by node) 16:34:52.080 | node: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.25' not found (required by node) 16:34:52.081 | node: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.28' not found (required by node) 16:34:52.127 | nvm is not compatible with the npm config "prefix" option: currently set to "" 16:34:52.129 | Run `npm config delete prefix` or `nvm use --delete-prefix v18.14.2` to unset it. 16:34:52.130 | Failed to install node version '18.14.2' 16:34:52.134 | Failed: build command exited with code: 1 16:34:53.060 | Failed: an internal error occurred
cloudflare unsupport node 18+, how do you fix this?
I have reviewed the following documents:
- https://github.com/cloudflare/pages-build-image/discussions/1#discussioncomment-4988959
- https://community.cloudflare.com/t/github-pages-astro-framework-node-js-v12-18-0-is-not-supported-by-astro/430276
- https://community.cloudflare.com/t/support-node-18-in-pages-or-allow-config/414797
However, it does support Node 17.
Cloudflare doesn't support Node 18, you can take a look at the currently supported platforms.: https://docs.astro.build/en/guides/deploy
Now, Cloudflare support higher node version but it's in Beta
Settings -> Builds& Deployments -> Build system version -> Configure Production build system
And I follow the https://docs.astro.build/en/guides/integrations-guide/cloudflare/ docs, I even cannot build successfully locally, So I temporally change to build a static file instead of an SSR file
Change to build Static File
export default defineConfig({
integrations: [
unocss(),
solidJs(),
],
output: 'server', // Delete this line
adapter: envAdapter(), // Delete this line
....
})
When I use SSR mode runs locally
I have tried node v16.20.1,v18.16.1,v20.1.0 all got same error message, if I change adapter to vercel() or netlify() it will build success
Simplified Configuration:
import cloudflare from '@astrojs/cloudflare';
export default defineConfig({
integrations: [
unocss(),
solidJs(),
],
output: 'server',
adapter: cloudflare()
....
})
Execute Command
astro build
I got the error:
05:05:39 PM [build] Rearranging server assets...
✘ [ERROR] Could not resolve "util"
node_modules/.pnpm/[email protected]/node_modules/undici/lib/fetch/file.js:4:26:
4 │ const { types } = require('util')
│ ~~~~~~
╵ "./util"
The package "util" wasn't found on the file system but is built into node. Are you trying to
bundle for node? You can use "platform: 'node'" to do that, which will remove this error.
✘ [ERROR] Could not resolve "assert"
node_modules/.pnpm/[email protected]/node_modules/undici/lib/fetch/dataURL.js:1:23:
1 │ const assert = require('assert')
╵ ~~~~~~~~
The package "assert" wasn't found on the file system but is built into node. Are you trying to
bundle for node? You can use "platform: 'node'" to do that, which will remove this error.
......
Error: Build failed with 67 errors:
node_modules/.pnpm/[email protected]/node_modules/busboy/lib/types/multipart.js:3:39: ERROR: Could not resolve "stream"
node_modules/.pnpm/[email protected]/node_modules/busboy/lib/types/urlencoded.js:3:29: ERROR: Could not resolve "stream"
node_modules/.pnpm/[email protected]/node_modules/undici/lib/api/api-connect.js:4:34: ERROR: Could not resolve "async_hooks"
node_modules/.pnpm/[email protected]/node_modules/undici/lib/api/api-pipeline.js:7:12: ERROR: Could not resolve "stream"
node_modules/.pnpm/[email protected]/node_modules/undici/lib/api/api-pipeline.js:14:34: ERROR: Could not resolve "async_hooks"
.....
If someone knows how to use SSR mode for build, I would be very grateful.
This project cannot run in static file mode, this will make API call doesn't work