Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

_interopRequireDefault2 is not a function #945

Open
bobrov-site opened this issue Nov 20, 2024 · 13 comments
Open

_interopRequireDefault2 is not a function #945

bobrov-site opened this issue Nov 20, 2024 · 13 comments
Labels
needs-reproduction Action needed: A valid reproduction of the issue needs to be added provider-authjs An issue with the authjs provider

Comments

@bobrov-site
Copy link

bobrov-site commented Nov 20, 2024

Environment

Reproduction

my [...].ts file

import { NuxtAuthHandler } from '#auth';
import CredentialsProvider from 'next-auth/providers/credentials';
import bcrypt from 'bcrypt'

export default NuxtAuthHandler({
    secret: useRuntimeConfig().authSecret,
    pages: {
        error: '/auth/error',
        signOut: '/?isLogout=true',
    },
    providers: [CredentialsProvider.default({
        name: 'credentials',
        credentials: {},
        async authorize(credentials: {email: string, password: string}){
            const user = await UserSchema.findOne({email: credentials.email})
            if (!user) {
                throw createError({
                    statusCode: 401,
                    statusMessage: 'User is not found',
                })
            }
            const isPasswordValid = await bcrypt.compare(credentials.password, user.password)
            if (!isPasswordValid) {
                throw createError({
                    statusCode: 401,
                    statusMessage: 'errorPasswordWrong',
                })
            }
            return {
                ...user.toObject(),
                password: ''
            }
        }
    })],
    session: {
        strategy: 'jwt',
    },
    callbacks: {
        async jwt({ token, user }) {
            if (user) {
                token.user = {
                    _id: user._id,
                    email: user.email,
                }
            }
            return token
        },
        async session({ session, token }) {
            const user = await UserSchema.findById(token.user._id)
            session.user = user
            return session
        },
    }
});

nuxt.config.ts

auth: {
    baseURL: `${process.env.NUXT_AUTH_ORIGIN}`,
    provider: {
        type: 'authjs',
        defaultProvider: 'credentials',
        addDefaultCallbackUrl: false,
    },
  },

Describe the bug

I have this an error

next-auth_react.js?v=ff837320:4048 Uncaught TypeError: _interopRequireDefault2 is not a function
at node_modules/next-auth/react/index.js (next-auth_react.js?v=ff837320:4048:24)
at __require (chunk-V4OQ3NZ2.js?v=ff837320:11:50)
at next-auth_react.js?v=ff837320:4628:16

Снимок экрана 2024-11-20 в 23 21 04

Additional context

When I run my nuxt application via npm run dev, I have this problem. But in production building I don't have it.

Logs

No response

@bobrov-site bobrov-site added bug A bug that needs to be resolved pending An issue waiting for triage labels Nov 20, 2024
@phoenix-ru
Copy link
Collaborator

Could you please share which version of next-auth do you have? It should be 4.21.1 as more recent versions cause build failures

@bobrov-site
Copy link
Author

@phoenix-ru it's 4.21.1

"next-auth": "^4.21.1",

I did like in documentation says

@bobrov-site
Copy link
Author

bobrov-site commented Nov 21, 2024

I got this trouble, when updated nuxt version to latest.

@phoenix-ru
Copy link
Collaborator

Thank you for sharing. I noticed you have a "lousy" specifier ^, which may update next-auth to a higher version. Could you please fix the version by doing

"next-auth": "4.21.1"

and rerun the install.

It should work if the version is correct. To check the correctness, run

npm why next-auth

You should see the same 4.21.1 version everywhere in the output.

If you use a correct version and the issue still persists, please share if you're using vite or webpack.

@phoenix-ru phoenix-ru added provider-authjs An issue with the authjs provider question A question about NuxtAuth and removed bug A bug that needs to be resolved pending An issue waiting for triage labels Nov 28, 2024
@bobrov-site
Copy link
Author

bobrov-site commented Nov 29, 2024

@phoenix-ru unfortunately, this not work me. I tried set next-auth to 4.21.1 and I have same problem. For now my package.json

"next-auth": "4.21.1",
"@sidebase/nuxt-auth": "^0.9.4",

When I use npm why next-auth I have next message:

[email protected]
node_modules/next-auth
  next-auth@"4.21.1" from the root project
  peer next-auth@"~4.21.1" from @sidebase/[email protected]
  node_modules/@sidebase/nuxt-auth
    dev @sidebase/nuxt-auth@"^0.9.4" from the root project

I am using vite for my project.

@bobrov-site
Copy link
Author

any updates?

@zoey-kaiser
Copy link
Member

Hi @bobrov-site 👋

I have not tested NuxtAuth with Nuxt version 3.14 yet. As there were some big breaking changes in 3.13 it would be related to this.

We are still working on resolving the issues that occured when upgrading to 3.13 in this PR: #942

Could you do me the favour of installing this version of NuxtAuth built from the PR mentoned above and checking if this resolves the issue?

npm i -D https://pkg.pr.new/@sidebase/nuxt-auth@c72268d

pnpm i -D https://pkg.pr.new/@sidebase/nuxt-auth@c72268d

yarn add --dev https://pkg.pr.new/@sidebase/nuxt-auth@c72268d

Note: You may need to completly uninstall and reinstall the new package mentioned above

@bobrov-site
Copy link
Author

@zoey-kaiser i will try soon your instructions. Thanks for replaying!

@bobrov-site
Copy link
Author

@zoey-kaiser i use npm and follow your command. This is not work for me.

Now my package.json looks now:

"@sidebase/nuxt-auth": "https://pkg.pr.new/@sidebase/nuxt-auth@c72268d",

@zoey-kaiser
Copy link
Member

Hi @bobrov-site, thats too bad 😢

Do you think you could create a minimal reproduction of the issue please? Without it I fear it will be hard for us to investigate the issue futhur.

@zoey-kaiser zoey-kaiser added needs-reproduction Action needed: A valid reproduction of the issue needs to be added and removed question A question about NuxtAuth labels Dec 13, 2024
Copy link

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.

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:

@bobrov-site
Copy link
Author

@zoey-kaiser i tried to create reproduction. https://stackblitz.com/edit/github-adkgbz7q?file=server%2Fapi%2Fauth%2F%5B...%5D.ts . In this case it's seems like okay.

But in my original project, I have mongo db and I have auth logic there. I cannot share to public with my project because inside I have secret data. How can we resolve this problem?

@phoenix-ru
Copy link
Collaborator

@bobrov-site You don't really need to share your data or application to reproduce. What is the output of the following command?

npm ls next-auth

On the reproduction you created it correctly returns

nuxt-app@ /home/projects/github-adkgbz7q
+-- @sidebase/[email protected]
| `-- [email protected] deduped
`-- [email protected]

Do you still get this problem if you install for example @sidebase/nuxt-auth@next?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-reproduction Action needed: A valid reproduction of the issue needs to be added provider-authjs An issue with the authjs provider
Projects
None yet
Development

No branches or pull requests

3 participants