I am trying to deploy a SvelteKit project from Github. It uses Auth.js and for previous successful deployments in vercel, I had to use latest node version (20.x) for Auth.js to work.
Node version: 20.11.0
Build command: npm run build
Build script: vite build
Build directory: /.svelte-kit/cloudflare
Build System version: 2
In the logs, the specified line 50 in hooks.server.js is trying to read a property: basePath.length. basePath is eventually set from the config parameter passed to SvelteKitAuth() function, an Auth.js library function. Auth.js by default sets it to "/auth".
This same configuration worked in Vercel. I have tried setting basePath to default value in code but the error still remains. The log parts related to the failure is given below:
23:15:18.367 Successfully installed @sveltejs/adapter-cloudflare.
23:15:18.368
23:15:18.368 If you plan on staying on this deployment platform, consider replacing @sveltejs/adapter-auto with @sveltejs/adapter-cloudflare. This will give you faster and more robust installs, and more control over deployment configuration.
23:15:18.369
23:15:19.038 TypeError: Cannot read properties of undefined (reading 'length')
23:15:19.038 at Object.handle (file:///opt/buildhome/repo/.svelte-kit/output/server/chunks/hooks.server.js:50:24)
23:15:19.038 at respond (file:///opt/buildhome/repo/.svelte-kit/output/server/index.js:2586:43)
23:15:19.038 at Server.respond (file:///opt/buildhome/repo/.svelte-kit/output/server/index.js:2849:12)
23:15:19.039 at generate_fallback (file:///opt/buildhome/repo/node_modules/@sveltejs/kit/src/core/postbuild/fallback.js:38:32)
23:15:19.039 at async MessagePort.<anonymous> (file:///opt/buildhome/repo/node_modules/@sveltejs/kit/src/utils/fork.js:22:16)
23:15:19.044
23:15:19.044 node:internal/event_target:1100
23:15:19.044 process.nextTick(() => { throw err; });
23:15:19.044 ^
23:15:19.046 Error: Could not create a fallback page — failed with status 500
23:15:19.046 at generate_fallback (file:///opt/buildhome/repo/node_modules/@sveltejs/kit/src/core/postbuild/fallback.js:53:8)
23:15:19.046 at async MessagePort.<anonymous> (file:///opt/buildhome/repo/node_modules/@sveltejs/kit/src/utils/fork.js:22:16)
23:15:19.046 Emitted 'error' event on Worker instance at:
23:15:19.047 at [kOnErrorMessage] (node:internal/worker:326:10)
23:15:19.047 at [kOnMessage] (node:internal/worker:337:37)
23:15:19.047 at MessagePort.<anonymous> (node:internal/worker:232:57)
23:15:19.047 at [nodejs.internal.kHybridDispatch] (node:internal/event_target:826:20)
23:15:19.047 at exports.emitMessage (node:internal/per_context/messageport:23:28)
23:15:19.047
23:15:19.047 Node.js v20.11.0
23:15:19.124 Failed: Error while executing user command. Exited with error code: 1
23:15:19.135 Failed: build command exited with code: 1
23:15:20.267 Failed: error occurred while running build command
I can provide more details if needed. Any help would be appreciated. Thanks in advance
What I did so far:
Changed Node version to latest from the default value.
Assigned "/auth" to SvelteKitAuth() function's config parameter property basePath.
Expected: The build should work with the given node version. It worked in Vercel.
Update: I could not get my project to build in cloudflare pages. It seems that the problem is somewhat related with cloudflare build environments inherent node version. In vercel, node 20.x is experimentally allowed. But in cloudflare pages, I had to setup a NODE_VERSION environment variable to get to node 20.x. This is the only difference between my successful vercel build and the failed cloudflare pages build.