TypeError: GoogleProvider is not a function when running with .ts script using tsx
For isolation purposes, the error occurs when calling the
getServerSession()
function from a .ts
script using the command "dotenv tsx ./tests/scripts/mock.ts"
The getServerAuthSession
function is defined as a helper function in ~/server/auth.ts
And the full error output is:
4 Replies
Does it need to be .tsx, afaik GoogleProvider is a react component
I was able to resolve this issue by writing in the full function definition of
GoogleProvider
defined in next-auth/providers/google
into the ~/server/auth.ts
file, like so.
This, will throw a different error when directly calling getServerAuthSession
from a script, but it resolves the TypeError in my actual use case, seen here:
I haven't been able to figure out what about the function being defined in
next-auth/providers/google
causes this error. From my understanding ESM supports default exports, which is what the npm package tsx
is able to compile.
https://github.com/privatenumber/tsx#readmeGitHub
GitHub - privatenumber/tsx: ⚡️ TypeScript Execute: Node.js enhanced...
⚡️ TypeScript Execute: Node.js enhanced to run TypeScript & ESM - GitHub - privatenumber/tsx: ⚡️ TypeScript Execute: Node.js enhanced to run TypeScript & ESM
converting the file to a
.tsx
produces the same error sadly.