admin管理员组文章数量:1277886
"next": "^15.1.4",
"next-auth": "^4.24.11",
Current problem doesn't appear on dev. It happens during execution next build
.
Building process crashes with error.
Creating an optimized production build ...
✓ Compiled successfully
✓ Linting and checking validity of types
Collecting page data ..TypeError: c is not a function
at 6105 (C:\AssetFlow\app\.next\server\app\api\auth\[...nextauth]\route.js:1:1383)
The main suspect is this file (route.js).
import NextAuth from "next-auth";
import GoogleProvider from "next-auth/providers/google";
import FacebookProvider from "next-auth/providers/facebook";
import GitHubProvider from "next-auth/providers/github";
const handler = NextAuth({
providers: [
FacebookProvider({
clientId: process.env.FACEBOOK_CLIENT_ID,
clientSecret: process.env.FACEBOOK_CLIENT_SECRET
}),
GoogleProvider({
clientId: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET
}),
GitHubProvider({
clientId: process.env.GITHUB_CLIENT_ID,
clientSecret: process.env.GITHUB_CLIENT_SECRET
}),
],
callbacks: {
async session({ session }) {
return session;
},
async signIn({ profile }) {
try {
if (profile?.["email"]) {
return true;
}
return false;
} catch (error) {
return false;
}
},
}
});
export { handler as GET, handler as POST };
If I disable minification for the build, the error will be TypeError: facebook is not a function
.
I even tried to run the output route.js from .next\server\app\api\auth\[...nextauth]\route.js
directly in NodeJS with debugger on, so I can see that facebook
is indeed not a function, but an object {__esModule: true, default: ƒ}.
So, the reason for the error is that NextJS bundler can't bundle auth providers properly.
How can I fix that?
"next": "^15.1.4",
"next-auth": "^4.24.11",
Current problem doesn't appear on dev. It happens during execution next build
.
Building process crashes with error.
Creating an optimized production build ...
✓ Compiled successfully
✓ Linting and checking validity of types
Collecting page data ..TypeError: c is not a function
at 6105 (C:\AssetFlow\app\.next\server\app\api\auth\[...nextauth]\route.js:1:1383)
The main suspect is this file (route.js).
import NextAuth from "next-auth";
import GoogleProvider from "next-auth/providers/google";
import FacebookProvider from "next-auth/providers/facebook";
import GitHubProvider from "next-auth/providers/github";
const handler = NextAuth({
providers: [
FacebookProvider({
clientId: process.env.FACEBOOK_CLIENT_ID,
clientSecret: process.env.FACEBOOK_CLIENT_SECRET
}),
GoogleProvider({
clientId: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET
}),
GitHubProvider({
clientId: process.env.GITHUB_CLIENT_ID,
clientSecret: process.env.GITHUB_CLIENT_SECRET
}),
],
callbacks: {
async session({ session }) {
return session;
},
async signIn({ profile }) {
try {
if (profile?.["email"]) {
return true;
}
return false;
} catch (error) {
return false;
}
},
}
});
export { handler as GET, handler as POST };
If I disable minification for the build, the error will be TypeError: facebook is not a function
.
I even tried to run the output route.js from .next\server\app\api\auth\[...nextauth]\route.js
directly in NodeJS with debugger on, so I can see that facebook
is indeed not a function, but an object {__esModule: true, default: ƒ}.
So, the reason for the error is that NextJS bundler can't bundle auth providers properly.
How can I fix that?
Share Improve this question asked Feb 23 at 22:01 splash27splash27 2,1076 gold badges26 silver badges54 bronze badges1 Answer
Reset to default 0Alright, I found the workaround.
- Delete
"type": "module",
from package.json. - If there are any imports in your
next.config.mjs
, then they should be done from .mjs files as well. For example, if you haveimport serverConfig from "./utils/serverConfig.js";
in yournext.config.mjs
then it should becomeimport serverConfig from "./utils/serverConfig.mjs";
. You have to rename imported files as well. - If you were importing the files from step 2 by name somewhere else, you will need to fix those imports as well.
Still feels like the problem initially is on the NextAuth side. I would expect those providers libraries to be bundled well like any other dependencies.
本文标签: nextjsProblem with NextAuth when building NextJS projectStack Overflow
版权声明:本文标题:next.js - Problem with NextAuth when building NextJS project - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741300921a2371083.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论