next-auth: Next.js build error
Describe the bug
I’m getting a build error in my nextjs app. When running next build
I end up getting this output.
$ next build
info - Loaded env from /Users/alex/code/my-project/.env
> [PWA] Compile client (static)
> [PWA] Auto register service worker with: /Users/alex/code/my-project/node_modules/next-pwa/register.js
> [PWA] Service worker: /Users/alex/code/my-project/public/sw.js
> [PWA] url: /sw.js
> [PWA] scope: /
> [PWA] Compile server
> Using external babel configuration
> Location: "/Users/alex/code/my-project/.babelrc"
Creating an optimized production build
Failed to compile.
./node_modules/typeorm/browser/driver/DriverFactory.js
Attempted import error: 'AuroraDataApiPostgresDriver' is not exported from './postgres/PostgresDriver'.
> Build error occurred
Error: > Build failed because of webpack errors
at build (/Users/alex/code/my-project/node_modules/next/dist/build/index.js:13:917)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Here’s my /api/auth/[...nextauth].js
import NextAuth from 'next-auth'
import Providers from 'next-auth/providers'
import adapter from 'next-auth/adapters'
const options = {
site: process.env.SITE || 'http://localhost:3000',
// Configure one or more authentication providers
providers: [
Providers.Twitter({
clientId: process.env.TWITTER_ID,
clientSecret: process.env.TWITTER_SECRET
}),
// Sign in with passwordless email link
Providers.Email({
server: process.env.MAIL_SERVER,
from: 'noreply@my-project.com'
}),
],
callbacks: {
session: async (session, user) => {
const { getUserByEmail } = await adapter.Default({}).getAdapter()
const { id } = await getUserByEmail(session.user.email)
session.user.id = id
return session
}
},
// A database is optional, but required to persist accounts in a database
database: process.env.USER_DB_URL,
}
export default (req, res) => NextAuth(req, res, options)
To Reproduce
next build
Expected behavior
When running locally, everything seems to work. I added NEXTAUTH_URL="https://my-project-alexcory.my-project.vercel.app"
to the .env
. Any ideas?
I just found https://github.com/typeorm/typeorm/issues/6110 and looks like it’s from typeorm@0.2.25
. Maybe switch from typeorm@^0.2.24
to typeorm@0.2.24
in package.json
?
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 27 (16 by maintainers)
I had the same problem. I realized after an hour it was me importing the library wrong. I had
import {signIn} from 'next-auth
and notimport {signIn} from 'next-auth/client'
@arunoda Oh no, I’m sorry to hear that! 😦
I wasn’t able to join the livestream yesterday as I had a call scheduled at the same time.
I’ll ask the folks at Next.js if they have any suggestions as to how we could detect the context something is running under so we can spit out a helpful error when this happens.
I had this exact same issue in a live stream. And I struggle for more than 30 min to find the root cause
I was still importing from
'next-auth/client'
so not sure if that was the problem for me.I have it pinned at
^3.0.1
and3.0.1
is installed currently. Might be worth removing theyarn.lock
file as well as thenode_modules
and.next
directories. After that let Yarn rebuild theyarn.lock
andnode_modules
withresolutions
set.I was getting that same ‘mongodb’ error when I just added the following to my
package.json
.This basically does what you were doing, but without needing to worry about Yarn making changes to it again.