Skip to content

Conversation

mridang
Copy link

@mridang mridang commented Aug 18, 2025

πŸ”— Linked issue

#1043

❓ Type of change

  • πŸ“– Documentation (updates to the documentation, readme or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

Updates nuxt-auth to support Nuxt 4. This is a breaking change - Nuxt 3 is no longer supported.

Dependencies bumped:

  • @nuxt/kit: ^3.17.6 β†’ ^4.0.0
  • @nuxt/schema: ^3.17.6 β†’ ^4.0.0
  • @nuxt/module-builder: ^0.8.4 β†’ ^1.0.2
  • nuxt: ^3.17.6 β†’ ^4.0.0
  • @antfu/eslint-config: ^4.16.2 β†’ ^5.0.0
  • @nuxt/eslint: ^1.7.1 (new)
  • oxlint: ^0.16.12 β†’ ^1.0.0
  • ts-essentials: ^9.4.2 β†’ ^10.1.1
  • vue-tsc: ^2.2.12 β†’ ^2.0.21
  • vite: ^7.0.0 (added)

Dependencies removed:

  • knitwork (replaced with native TS interface generation)
  • scule
  • @nuxtjs/eslint-config-typescript (replaced with @nuxt/eslint)

Code Updates:

  • Replaced knitwork.genInterface with native TypeScript interface generation
  • Improved type safety in helper functions with non-null assertions
  • Updated module exports to ESM-only (removed CommonJS support)
  • Fixed TypeScript file extensions (.d.ts β†’ .d.mts)

Documentation:

  • Updated all references from "Nuxt 3" to "Nuxt 4" across README, docs, and comments
  • Updated meta descriptions and titles to reflect Nuxt 4 support

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have added tests (if possible).
  • I have updated the documentation accordingly.

mridang added 10 commits July 28, 2025 23:01
This commit addresses a warning issued by `@nuxt/module-builder` during the 'prepack' build process. The warning indicated that the top-level 'types' field in 'package.json' is no longer required for modern bundler TypeScript module resolution.

By removing this redundant field, the 'package.json' now adheres to current best practices for module declaration, where type entry points are primarily defined within the 'exports' map. This ensures a cleaner and more consistent module resolution experience for consumers using modern tools and Node.js versions.
This commit finalizes the refactoring of the package's module entry points in package.json by removing the top-level "main" field. This change directly addresses a recurring warning issued by `@nuxt/module-builder` during the `prepack` build process, which indicated that this field is no longer required for Nuxt 3+ applications.

The "main" field historically defined the primary entry point for packages consumed via CommonJS `require()`. However, with the adoption of the "exports" field in package.json (a Node.js feature), this field now takes precedence in defining package entry points for both CommonJS and ECMAScript Modules. For modern Nuxt applications (Nuxt 3+ and Nuxt 4), the build system and underlying Nitro server overwhelmingly prefer and resolve modules using ESM (`.mjs` files) via the `exports.import` condition. The presence of the "main" field becomes redundant in such contexts and triggers strict warnings from module builders like `@nuxt/module-builder`.

This change ensures that the package.json now primarily relies on the "exports" field to define a single, modern ESM entry point (`./dist/module.mjs`). This aligns the module's declaration with the current best practices for publishing packages intended for contemporary JavaScript ecosystems, particularly those using ES Modules.

The primary benefit of this change is to eliminate the persistent `ERROR Exiting with code (1)` during `pnpm run prepack`, which was directly linked to the warnings about redundant CommonJS/legacy declarations. It also contributes to a cleaner `package.json` and ensures better compatibility and predictability when consumed by modern bundlers, TypeScript, and Node.js versions that adhere to the "exports" map specification.

While this change streamlines the module for ESM-first consumption, if specific legacy CommonJS environments or tools were strictly relying on the "main" field, those particular use cases would need separate evaluation. However, for the primary use case with Nuxt 4, this refined `package.json` is optimized for seamless integration.
The scule package has been removed from the project's dependencies as it was no longer being utilised within the codebase.

This cleanup simplifies the dependency tree and reduces the overall installation size, contributing to better project maintenance and a leaner package. This is a non-breaking change with no impact on the module's functionality.
The `nitropack` package is only used within the module for its TypeScript type definitions (import type). It is not a true runtime dependency.

Type-only imports are erased during compilation, and the module uses a local stub for `defineNitroPlugin` to avoid needing a runtime import from `nitropack`.

Therefore, moving `nitropack` to devDependencies correctly declares its purpose as a tool for development-time type checking.

This cleans up the production dependencies for end-users of this module.
The `knitwork` package was used for a single function, `genInterface`, to generate a TypeScript interface string for the local provider's session data.

This implementation has been replaced with a concise, inline solution using `Object.entries` and `map`. This change removes an unnecessary dependency, making the module lighter and easier to maintain without sacrificing functionality.
Copy link

pkg-pr-new bot commented Aug 18, 2025

Open in StackBlitz

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

commit: 55315e5

@jonny64bit
Copy link

jonny64bit commented Aug 19, 2025

I've used this from the point of view of a local setup with an external backend and all seems to be working as expected. Thanks for sorting this auth for v4.

@mridang
Copy link
Author

mridang commented Aug 25, 2025

@sidebase or any of the maintainers - any chance of seeing this merged?

@zoey-kaiser
Copy link
Member

Hi everyone πŸ‘‹

Thanks for opening this PR! I agree that the migration to Nuxt 4 will be an important step for the future.

However, I am a little hesitent to fully migrate everything over at the moment. A lot of apps still run on Nuxt 3 and it is also still getting releases. Therefore we should still support Nuxt 3 to ensure we can push fixes and security patches.

Inside your linked issue and most of my tests I can see that most use-cases of NuxtAuth in Nuxt 4 are working without any issues. Did you run into issues that require a full upgrade to Nuxt 4 internals?

Aside from this, you can already use the pkg.new package that was created based off this PR for now:

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants