nuxt auth does not work with cloudflare pages (an by extension NuxtHub)
Environment
- Operating System: Darwin
- Node Version: v23.2.0
- Nuxt Version: 3.15.4
- CLI Version: 3.23.1
- Nitro Version: 2.11.6
- Package Manager: [email protected]
- Builder: -
- User Config: -
- Runtime Modules: -
- Build Modules: -
Reproduction
cant deploy through nuxthub/cf pages with auth
Describe the bug
the n.default throws an error that breaks it:
{ "wallTime": 4, "cpuTime": 3, "truncated": false, "executionModel": "stateless", "outcome": "ok", "scriptVersion": { "id": "5e4c3d51-c954-487c-a0bb-ed7c21c28fca" }, "scriptName": "pages-worker--5512482-preview", "diagnosticsChannelEvents": [], "exceptions": [], "logs": [ { "message": [ "[nuxt] [request error] [unhandled] [500]", "n.default is not a function\n" ], "level": "error", "timestamp": 1742471759976 } ], "eventTimestamp": 1742471759976, "event": { "request": { "url": "https://622be7a9.serp-wiki.pages.dev/api/auth/session", "method": "GET", "headers": { "accept": "/", "accept-encoding": "gzip, br", "accept-language": "en-US,en;q=0.9", "cf-connecting-ip": "2400:2410:3f64:7a00:14a8:5c43:e972:dd61", "cf-ipcountry": "JP", "cf-ray": "92350613debbfd43", "cf-visitor": "{"scheme":"https"}", "connection": "Keep-Alive", "host": "622be7a9.serp-wiki.pages.dev", "priority": "u=1, i", "sec-ch-ua": ""Not(A:Brand";v="99", "Google Chrome";v="133", "Chromium";v="133"", "sec-ch-ua-mobile": "?0", "sec-ch-ua-platform": ""macOS"", "sec-fetch-dest": "empty", "sec-fetch-mode": "cors", "sec-fetch-site": "same-origin", "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36", "x-forwarded-proto": "https", "x-real-ip": "2400:2410:3f64:7a00:14a8:5c43:e972:dd61" }, "cf": { "requestHeaderNames": {}, "httpProtocol": "HTTP/3", "tlsCipher": "AEAD-AES128-GCM-SHA256", "continent": "AS", "asn": 17676, "clientAcceptEncoding": "gzip, deflate, br, zstd", "tlsClientExtensionsSha1": "NThlM28bxCJZ638P2eppWTILjCQ=", "verifiedBotCategory": "", "country": "JP", "tlsClientAuth": { "certIssuerDNLegacy": "", "certIssuerSKI": "", "certSubjectDNRFC2253": "", "certSubjectDNLegacy": "", "certFingerprintSHA256": "", "certNotBefore": "", "certSKI": "", "certSerial": "", "certIssuerDN": "", "certVerified": "NONE", "certNotAfter": "", "certSubjectDN": "", "certPresented": "0", "certRevoked": "0", "certIssuerSerial": "", "certIssuerDNRFC2253": "", "certFingerprintSHA1": "" }, "requestPriority": "", "tlsVersion": "TLSv1.3", "colo": "NRT", "timezone": "Asia/Tokyo", "region": "Tokyo", "longitude": "139.68990", "edgeRequestKeepAliveStatus": 1, "tlsClientRandom": "EdAXJEuaxw2c287q0kJjGWFblbB+ppWxcs3otDQPmes=", "latitude": "35.68930", "regionCode": "13", "asOrganization": "SoftBank Corp.", "tlsClientHelloLength": "1529", "pagesHostName": "622be7a9.serp-wiki.pages.dev", "botManagement": { "corporateProxy": false, "verifiedBot": false, "jsDetection": { "passed": false }, "staticResource": false, "detectionIds": {}, "score": 99 } } }, "response": { "status": 500 } }, "id": 2 }
Additional context
No response
Logs
Hello 👋
Please provide a reproduction for this issue 🙏
How can I create a reproduction?
Please use one of the following links to reproduce your issue.
- https://stackblitz.com/github/nuxt/starter/tree/v3-stackblitz
- https://codesandbox.io/s/github/nuxt/starter/v3-codesandbox
Please ensure that the reproduction is as minimal as possible. This will allow us to isolate the issue as best as possible.
Here are some more amazing posts about the importance of reproductions:
Hi @devinschumacher. I can't unfortunately take a proper look into the issue without getting a bit more specifics. We don't deploy to CF ourselves, so I can suggest you two options:
- Conduct your own investigation of what goes wrong and suggest what NuxtAuth needs to do to fix your usecase, either via adding details to this issue or even opening a fix PR.
- Contact me privately (via email to [email protected]), so that I can request some details which you might not want to publish.
I'm running into the same issue.
GitHub Issue: ns.default is not a function error with @sidebase/nuxt-auth in production
Issue Summary
When using @sidebase/nuxt-auth with Google authentication, the application works perfectly in local development but fails in production with the following error:
ERROR [request error] [unhandled] [GET] https://test.example/api/auth/session
{ message: 'ns.default is not a function', statusCode: 500 }
Environment
- Works in: Local development environment
- Fails in: Production environment
- Nuxt version: 3.16.0
- @sidebase/nuxt-auth version: 0.10.1
Configuration
Using Google OAuth with the following setup:
// server/api/auth/[...].ts
import { NuxtAuthHandler } from '#auth'
import GoogleProvider from 'next-auth/providers/google'
const config = useRuntimeConfig()
export default NuxtAuthHandler({
debug: true,
providers: [
GoogleProvider.default({
clientId: config.oauth.google.clientId,
clientSecret: config.oauth.google.clientSecret,
authorization: {
params: {
prompt: 'consent',
access_type: 'offline',
response_type: 'code',
},
},
}),
],
pages: {
signIn: '/login',
},
})
Reproduction steps
- Application runs fine locally with the above configuration
- When deployed to production, attempting to access the session causes a 500 error
- The error specifically happens when making a GET request to
/api/auth/session
Additional context
- There appears to be a module resolution conflict between
next-authand@auth/coreproviders - TypeScript shows type conflicts between these packages:
Type 'OAuthConfig<any>' is not assignable to type 'Provider' Type 'OIDCConfig<any>' is not assignable to type 'Provider' - The error in production suggests that the default export from a namespace is not a function, likely related to how module exports are handled differently in production builds
Attempted solutions
- Added transpilation for auth modules in nuxt.config.ts
- Tried using both
next-auth/providers/googleand@auth/core/providers/google - Both have type conflicts but the application runs locally
Any help resolving this production-only issue would be greatly appreciated!
@zaidmasri You should not be using @auth/core yet as it is incompatible with NuxtAuth yet (see #673 for progress).
When you use next-auth, you need to ensure that your version is exactly 4.21.1, otherwise you wouldn't get it to work (they made breaking changes in a minor release, nothing we can do to mitigate this).
@phoenix-ru & @devinschumacher
I discovered that Cloudflare Workers provide a subset of Node.js's API and not the full thing. It might be just a matter of time until they get around to it or if you find the hack please let me know.
@zaidmasri Is there an upstream issue in the Nuxt repo or in the Cloudflare repo? Could you please link to it here?
@phoenix-ru
I found a closed issue on this repo #378. Particularly, this comment & this comment.
Since nuxt-auth uses next-auth I was looking at their issues and found this.