Sveltekit Build failed with error possibly in Auth.js

Hi, I am trying to deploy a SvelteKit project from Github. It uses Auth.js and for previous successful deployments, I had to use latest node version (20.x) for Auth.js to work.
I changed NODE_VERSION env variable to 20.x after the first failure, however the build still fails. The specified line 50 in hooks.server.js is possibly 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".
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. I think it could possibly be something wrong with Auth.js, however the same build configuration worked fine in vercel. Any help will be appreciated.
Thanks in advance!

That error means that you are trying to read properties of something undefined. That is typical when you are connecting to an API or DB, and it didn’t find the resource. You must handle the errors before getting to that to know exactly what is the resource that is failing. I would check out all the elements on which you are accessing to the .length.