Packages

@nuxt/module-builder

1.0.4 · 11 Nov 2026MIT146.9k / weekRepositoryHomepagenpmAtom feed

Your version

1.0.0

major4 Apr 2025Where it was published

1.0.4 is the newest release of 1.x.

In short

8 breaking2 new9 fixed26 internal

  • Breaking

    With the release of unbuild v3, the EOL status of Nuxt 2, and looking forward to Nuxt 4, we're taking the opportunity to release v1 of @nuxt/module-builder, with a range of breaking changes.

  • Breaking

    Upgrade to unbuild v3 This major upgrade brings significant changes to the build proces but should be significantly better.

  • Breaking

    Removal of Node10 module resolution and CommonJS output As Nuxt 2 has reached EOL, we no longer generate CJS by default, and we have also removed the 'CJS bridge' feature that polyfilled __filename and __dirname.

  • Breaking

    Type errors. The module builder will now error if there are type errors when generating your runtime/* files. (Previously warnings were logged but your build would have succeeded.) Errors you receive aren't caused by the upgrade, but you might need to correct any issues before your module will build again.

  • Breaking

    Set "type": "module" in your package.json

  • Breaking

    Update any mentions of .cjs files in your package.json

  • Breaking

    ⚠️ Upgrade to unbuild v3

  • Breaking

    ⚠️ Remove support for node10 resolution + cjs

Release note

With the release of unbuild v3, the EOL status of Nuxt 2, and looking forward to Nuxt 4, we're taking the opportunity to release v1 of @nuxt/module-builder, with a range of breaking changes.

Breaking Changes

  • Breaking

    Upgrade to unbuild v3
    This major upgrade brings significant changes to the build proces but should be significantly better.

  • Breaking

    Removal of Node10 module resolution and CommonJS output
    As Nuxt 2 has reached EOL, we no longer generate CJS by default, and we have also removed the 'CJS bridge' feature that polyfilled __filename and __dirname.

  • Breaking

    Type errors. The module builder will now error if there are type errors when generating your runtime/* files. (Previously warnings were logged but your build would have succeeded.) Errors you receive aren't caused by the upgrade, but you might need to correct any issues before your module will build again.

Migration Guide

Replacing __filename and __dirname

We no longer polyfill these CommonJS variables. Instead, use the createResolver utility from @nuxt/kit:

import { createResolver } from '@nuxt/kit'

// Instead of __dirname and __filename
const resolver= createResolver(import.meta.url)
const runtimeDir = resolver.resolve('./runtime')

Module Resolution Changes

We no longer officially support Node10 module resolution, meaning you should remove the types/type field from your package.json. If you need to maintain compatibility with older Node.js versions or systems expecting CommonJS, you can use the typesVersions field in your package.json.

This field allows typing subpath exports (like my-module/utils) even with older moduleResolution settings. Regardless, we recommend all Nuxt users to use Bundler module resolution.

{
  "typesVersions": {
    "*": {
      ".": [
        "dist/index.d.mts"
      ],
      "some-subpath": [
        "dist/some-subpath.d.mts"
      ]
    }
  }
}

ESM-only Output

We no longer generate CommonJS (.cjs) output files by default, as this was primarily needed for Nuxt 2 compatibility. You should:

  • Breaking

    Set "type": "module" in your package.json

  • Breaking

    Update any mentions of .cjs files in your package.json

For example:

+ "type": "module",
  "exports": {
    ".": {
-    "types": "./dist/types.d.ts",
+    "types": "./dist/types.d.mts",
      "import": "./dist/module.mjs",
-     "require": "./dist/module.cjs"
    },
-   "./utils": {
-     "types": "./dist/utils.d.mts",
-     "import": "./dist/utils.mjs",
-     "require": "./dist/utils.cjs"
+   "./utils": "./dist/utils.mjs"
  },
- "main": "./dist/module.cjs",
+ "main": "./dist/module.mjs",
- "types": "./dist/module.d.ts",
+ "typesVersions": {
+   "*": {
+     ".": [
+       "./dist/types.d.mts"
+     ],
+     "utils": [
+       "./dist/utils.d.mts"
+     ]
+   }
+ },
  "files": [
-   "utils.d.ts"
    "dist"
  ],

Configuring unbuild

You can still customize the build process by extending the unbuild configuration in your buildOptions.

To customize/extend the unbuild configuration you can add a build.config.ts in the root of your project:

import { defineBuildConfig } from 'unbuild'

export default defineBuildConfig({
  // set additional configuration or customize using hooks
  rollupOptions: {
    // for example, if you wish to continue to generate `.cjs` output
    emitCJS: true
  }
})

Changelog

compare changes

Enhancements

  • Breaking

    ⚠️ Upgrade to unbuild v3

  • Breaking

    ⚠️ Remove support for node10 resolution + cjs

  • build: Ignore test + story files in runtime/ directory

  • Add support for type exports in module re-exports

Fixes

  • Mark nuxi as optional peerDep

  • Drop @nuxt/kit peer dependency & remove optionality for nuxi

  • build: Handle windows path names

  • build: Apply resolved tsconfig to dts

  • Handle node10 resolution + add attw test

  • Update warnings

  • Support more than one line of type exports

  • Split re-exports across multiple lines

  • Support star exports

CI

Breaking Changes

  • Breaking

    ⚠️ Upgrade to unbuild v3

  • Breaking

    ⚠️ Remove support for node10 resolution + cjs

A whole project to check? Paste its package.json in the dependency check: every deprecated, outdated or vulnerable dependency, with what to upgrade to. Free, no account.