Module not found w/ next-auth
Answered
Mugger Crocodile posted this in #help-forum
Mugger CrocodileOP
folder structure
auth.ts:
pages.tsx
route.ts
error:
app
api
auth
[...nextauth]
route.ts
account
guilds
page.tsx
lib
auth.ts
auth.ts:
import NextAuth from "next-auth";
import DiscordProvider from "next-auth/providers/discord";
import "dotenv/config";
export const { auth, handlers: { GET, POST } } = NextAuth({
providers: [
DiscordProvider({
clientId: process.env.CLIENT_ID ?? "",
clientSecret: process.env.CLIENT_SECRET ?? ""
})
],
secret: process.env.NEXTAUTH_URL
});
pages.tsx
import { redirect } from "next/navigation.js";
import { auth } from "@/app/lib/auth.js";
import styles from "../../page.module.css";
export default async function GuildsPage() {
const session = await auth();
if (!session) redirect("/api/auth/signin");
return (
<main className={styles.description}>
<p>
Guilds Page
</p>
<p>Welcome {session.user?.name}!</p>
</main>
);
}
route.ts
export { GET, POST } from "@/app/lib/auth.js";
error:
⨯ ./src/app/api/auth/[...nextauth]/route.ts:1:0
Module not found: Can't resolve '@/app/lib/auth.js'
> 1 | export { GET, POST } from "@/app/lib/auth.js";
Answered by Mugger Crocodile
i solved the issue by using
"allowImportingTsExtensions": true,
and setting auth.js to auth.ts8 Replies
Mugger CrocodileOP
Using Bun
Next: 14.0.4
NextAuth: 5.0.0-beta.5
Next: 14.0.4
NextAuth: 5.0.0-beta.5
Ive tried using "use client" and "use server". doesnt help
could you try with npm/yarn/pnpm?
Mugger CrocodileOP
sure
nope...
still causing an error
export { GET, POST } from "@/app/lib/auth";
Mugger CrocodileOP
i solved the issue by using
"allowImportingTsExtensions": true,
and setting auth.js to auth.tsAnswer