Skip to content

Issue with @sidebase/nuxt-auth and next-auth: next-auth/core Import Fails + Runtime Error #953

Open
@PawelRod

Description

@PawelRod

Environment

Nuxt version: 3.14.1592
Nitro version: 2.10.4
@sidebase/nuxt-auth version: 0.9.4
next-auth version: 4.21.1
Node.js version: 20.18.1 (LTS)
npm version: 9.8.1
OS: macOS 15.0.1

Reproduction

  1. Install dependencies:

npm install @sidebase/nuxt-auth@0.9.4 next-auth@4.21.1

  1. Configure nuxt.config.ts:
import vuetify from 'vite-plugin-vuetify';

export default defineNuxtConfig({
  ssr: true,
  modules: ["@sidebase/nuxt-auth"],
  vite: {
    resolve: {
      alias: {
        "next-auth/core": "next-auth",
      },
    },
  },
  nitro: {
    preset: "node-server",
    externals: {
      inline: ["@sidebase/nuxt-auth", "next-auth"],
    },
  },
  runtimeConfig: {
    authSecret: process.env.AUTH0_CLIENT_SECRET || "super-secret-key",
    public: {
      auth0Domain: process.env.AUTH0_DOMAIN,
      auth0ClientId: process.env.AUTH0_CLIENT_ID,
      auth0Audience: process.env.AUTH0_AUDIENCE,
      apiPath: process.env.API_PATH,
    },
  },
});
  1. Add the following API routes:
  • server/api/auth/[...].ts:
import Auth0Provider from "next-auth/providers/auth0";
import { NuxtAuthHandler } from "#auth";

export default NuxtAuthHandler({
  secret: process.env.AUTH0_CLIENT_SECRET || "my-superb-secret",
  providers: [
    Auth0Provider.default({
      clientId: process.env.AUTH0_CLIENT_ID,
      clientSecret: process.env.AUTH0_CLIENT_SECRET,
      issuer: process.env.AUTH0_DOMAIN,
    }),
  ],
});
  • server/api/token.get.ts:
import { getToken } from "#auth";
export default eventHandler(async (event) => {
  const token = await getToken({ event });
  return token || "no token present";
});
  1. Run the development server:

npm run dev

  1. Observe the warnings and errors in the terminal.

Describe the bug

When using @sidebase/nuxt-auth with next-auth, the following issues arise:

  1. Warnings during build:
WARN  [plugin node-resolve] Could not resolve import "next-auth/core" in /node_modules/@sidebase/nuxt-auth/dist/runtime/server/services/authjs/nuxtAuthHandler.js using exports defined in /node_modules/next-auth/package.json.
WARN  "next-auth/core" is imported by "node_modules/@sidebase/nuxt-auth/dist/runtime/server/services/authjs/nuxtAuthHandler.js", but could not be resolved – treating it as an external dependency.
  1. Runtime error during server startup:
	ERROR [worker reload] [worker init] /path/to/project/.nuxt/dev/index.mjs failed
ERROR [nitro] [uncaughtException] _interopRequireDefault$1 is not a function
  at <anonymous> (node_modules/next-auth/utils/logger.js:12:24)

These errors persist across various configurations and attempts to resolve the next-auth/core module.

Additional context

• I have tried multiple versions of next-auth (e.g., 4.21.1, 4.24.10) and the issue persists.
• Alias for next-auth/core → next-auth was added in vite.resolve.alias.
• Ensured all environment variables for Auth0 are set correctly:

AUTH0_DOMAIN=example-domain.auth0.com
AUTH0_CLIENT_ID=example-client-id
AUTH0_CLIENT_SECRET=example-client-secret
AUTH0_AUDIENCE=https://example-api.com/
API_PATH=https://example-api.com

Request for Assistance

  1. Is there a specific version of next-auth required for @sidebase/nuxt-auth@0.9.4?
  2. Are there any additional steps to resolve the next-auth/core import issue?
  3. Is this configuration missing anything critical for proper functionality?

Logs

Build Warnings

 WARN  [plugin node-resolve] Could not resolve import "next-auth/core" in /node_modules/@sidebase/nuxt-auth/dist/runtime/server/services/authjs/nuxtAuthHandler.js using exports defined in /node_modules/next-auth/package.json.
 WARN  "next-auth/core" is imported by "node_modules/@sidebase/nuxt-auth/dist/runtime/server/services/authjs/nuxtAuthHandler.js", but could not be resolved – treating it as an external dependency.


Runtime Errors

 ERROR  [worker reload] [worker init] /path/to/project/.nuxt/dev/index.mjs failed
 ERROR  [nitro] [uncaughtException] _interopRequireDefault$1 is not a function
   at <anonymous> (node_modules/next-auth/utils/logger.js:12:24)

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionA question about NuxtAuth

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions