fix(kit,nuxt,rspack,schema,webpack): add `.mts` file extension in resolver by OrbisK · Pull Request #33845 · nuxt/nuxt · GitHub
Skip to content

fix(kit,nuxt,rspack,schema,webpack): add .mts file extension in resolver - #33845

Merged
danielroe merged 10 commits into
nuxt:mainfrom
OrbisK:fix/extensions-mts
Jul 19, 2026
Merged

danielroe merged 10 commits into
nuxt:mainfrom
OrbisK:fix/extensions-mts

Conversation

@OrbisK

@OrbisK OrbisK commented Dec 10, 2025 •

Copy link
Copy Markdown
Member

📚 Description

Related to nuxt/ui#5630

I was wondering why .mts is missing here 🤔

Note

There may be other places in which we can add '.mts'.

@OrbisK
OrbisK requested a review from danielroe as a code owner December 10, 2025 08:20
@bolt-new-by-stackblitz

Copy link
Copy Markdown

@github-actions github-actions Bot added 4.x 🐛 bug Something isn't working as expected labels Dec 10, 2025
@coderabbitai

coderabbitai Bot commented Dec 10, 2025 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

This PR expands and reorders file-extension lists used by Kit module, plugin, and path resolvers. JSX and TSX extensions are added to module-loading paths, while the granular resolver fallback also includes JavaScript, JSX, TSX, MTS, and CTS candidates. The generate-types test fixture is updated to match the expanded ordering. No public signatures or control flow are changed.

Possibly related PRs

  • nuxt/nuxt#35233 — Updates TypeScript path substitution and generate-types coverage for .mts and .cts files.
  • nuxt/nuxt#35235 — Modifies Nuxt type-path extension resolution in the same area.
  • nuxt/nuxt#35511 — Changes the granular path-resolution probing affected by this PR’s extension candidates.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly describes the main change: adding .mts support in resolver logic.
Description check ✅ Passed The description is directly related to the resolver extension change and its motivation.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pkg-pr-new

pkg-pr-new Bot commented Dec 10, 2025 •

Copy link
Copy Markdown

Open in StackBlitz

@nuxt/kit

npm i https://pkg.pr.new/@nuxt/kit@33845

@nuxt/nitro-server

npm i https://pkg.pr.new/@nuxt/nitro-server@33845

nuxt

npm i https://pkg.pr.new/nuxt@33845

@nuxt/rspack-builder

npm i https://pkg.pr.new/@nuxt/rspack-builder@33845

@nuxt/schema

npm i https://pkg.pr.new/@nuxt/schema@33845

@nuxt/vite-builder

npm i https://pkg.pr.new/@nuxt/vite-builder@33845

@nuxt/webpack-builder

npm i https://pkg.pr.new/@nuxt/webpack-builder@33845

commit: f40b791

@codspeed

codspeed Bot commented Dec 10, 2025 •

Copy link
Copy Markdown

Merging this PR will degrade performance by 10.16%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

❌ 1 regressed benchmark
✅ 20 untouched benchmarks
⏩ 3 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
❌ initial production build in the minimal test fixture 1.8 s 2 s -10.16%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing OrbisK:fix/extensions-mts (f40b791) with main (8d47e72)

Open in CodSpeed

Footnotes

  1. 3 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

Comment thread packages/schema/src/config/common.ts Outdated
Co-authored-by: Alexander Lichter <github@lichter.io>
Comment thread packages/schema/src/config/common.ts Outdated
extensions: {
$resolve: (val): string[] => {
const extensions = ['.js', '.jsx', '.mjs', '.ts', '.tsx', '.vue']
const extensions = ['.js', '.jsx', '.mjs', '.ts', '.tsx', '.mts', '.vue']

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe should we have an unique const (named liek DEFAULT_JS_FILE_EXT) for all js file extensions to reduce risks ?
And this could be done for other kind of file extensions too by having one for jsx for example

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need this for schema and kit, so we have to duplicate it?

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/nuxt/src/core/utils/types.ts (1)

6-20: Extend suffix-stripping regex to cover TSX/JSX files

resolveTypePath includes .tsx and .jsx in the extensions array but the subpath branch only strips classic JS/TS suffixes:

return r.replace(/(?:\.d)?\.[mc]?[jt]s$/, '')

Should a type entry resolve to .tsx or .jsx, the extension will remain intact, unlike .js, .ts, .mjs, .cjs, .mts, or .cts cases. This creates an asymmetry that could affect downstream path handling in the TypeScript configuration.

Extend the regex to include TSX/JSX:

-      return r.replace(/(?:\.d)?\.[mc]?[jt]s$/, '')
+      return r.replace(/(?:\.d)?\.[mc]?(?:[jt]s|[jt]sx)$/, '')

This simple pattern avoids catastrophic backtracking and ensures consistent behaviour across all resolvable extensions.

🧹 Nitpick comments (2)
packages/kit/src/resolve.ts (1)

201-202: Default resolver extensions correctly expanded (consider centralising)

The richer default extensions set is sensible and backwards compatible (existing precedence for .ts is preserved while adding .js, TSX/JSX and MTS/CTS plus .json). To avoid future drift between the various extension arrays (here, in kit/module install, Vite schema, webpack preset, etc.), it may be worth hoisting a shared constant for the canonical JS/TS extension set and reusing it across these call sites.

packages/nuxt/src/core/external-config-files.ts (1)

40-42: External webpack config detection correctly extended

Including .mts and .cts (and normalising .coffee with a dot) makes the webpack external-config check consistent with the Vite/nitro checks and the central resolver behaviour. If more config checks are added in future, you might consider sharing a common extension set to avoid divergence, but this change itself is sound.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ab9a613 and 84b98fb.

📒 Files selected for processing (11)
  • packages/kit/src/internal/esm.ts (2 hunks)
  • packages/kit/src/module/install.ts (2 hunks)
  • packages/kit/src/plugin.ts (1 hunks)
  • packages/kit/src/resolve.ts (1 hunks)
  • packages/kit/test/generate-types.spec.ts (1 hunks)
  • packages/nuxt/src/core/external-config-files.ts (1 hunks)
  • packages/nuxt/src/core/utils/types.ts (1 hunks)
  • packages/nuxt/test/page-metadata.test.ts (1 hunks)
  • packages/schema/src/config/common.ts (1 hunks)
  • packages/schema/src/config/vite.ts (1 hunks)
  • packages/webpack/src/presets/base.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/schema/src/config/common.ts
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{ts,tsx,vue}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Follow standard TypeScript conventions and best practices

Files:

  • packages/nuxt/test/page-metadata.test.ts
  • packages/kit/src/internal/esm.ts
  • packages/kit/src/plugin.ts
  • packages/kit/test/generate-types.spec.ts
  • packages/kit/src/resolve.ts
  • packages/webpack/src/presets/base.ts
  • packages/kit/src/module/install.ts
  • packages/nuxt/src/core/external-config-files.ts
  • packages/nuxt/src/core/utils/types.ts
  • packages/schema/src/config/vite.ts
**/*.{ts,tsx,js,jsx,vue}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

**/*.{ts,tsx,js,jsx,vue}: Use clear, descriptive variable and function names
Add comments only to explain complex logic or non-obvious implementations
Keep functions focused and manageable (generally under 50 lines), and extract complex logic into separate domain-specific files
Remove code that is not used or needed
Use error handling patterns consistently

Files:

  • packages/nuxt/test/page-metadata.test.ts
  • packages/kit/src/internal/esm.ts
  • packages/kit/src/plugin.ts
  • packages/kit/test/generate-types.spec.ts
  • packages/kit/src/resolve.ts
  • packages/webpack/src/presets/base.ts
  • packages/kit/src/module/install.ts
  • packages/nuxt/src/core/external-config-files.ts
  • packages/nuxt/src/core/utils/types.ts
  • packages/schema/src/config/vite.ts
**/*.{test,spec}.{ts,tsx,js}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Write unit tests for core functionality using vitest

Files:

  • packages/nuxt/test/page-metadata.test.ts
  • packages/kit/test/generate-types.spec.ts
🧠 Learnings (11)
📓 Common learnings
Learnt from: GalacticHypernova
Repo: nuxt/nuxt PR: 29661
File: packages/kit/src/template.ts:227-229
Timestamp: 2024-11-28T21:22:40.496Z
Learning: In `packages/kit/src/template.ts`, when updating the `EXTENSION_RE` regular expression for TypeScript configuration, avoid using patterns like `(\.\w+)+$` as they can result in catastrophic backtracking.
Learnt from: CR
Repo: nuxt/nuxt PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-11-25T11:42:16.132Z
Learning: Applies to **/*.{ts,tsx,vue} : Follow standard TypeScript conventions and best practices
Learnt from: CR
Repo: nuxt/nuxt PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-11-25T11:42:16.132Z
Learning: Applies to **/*.{ts,tsx,js,jsx,vue} : Use error handling patterns consistently
📚 Learning: 2024-11-28T21:22:40.496Z
Learnt from: GalacticHypernova
Repo: nuxt/nuxt PR: 29661
File: packages/kit/src/template.ts:227-229
Timestamp: 2024-11-28T21:22:40.496Z
Learning: In `packages/kit/src/template.ts`, when updating the `EXTENSION_RE` regular expression for TypeScript configuration, avoid using patterns like `(\.\w+)+$` as they can result in catastrophic backtracking.

Applied to files:

  • packages/nuxt/test/page-metadata.test.ts
  • packages/kit/src/internal/esm.ts
  • packages/kit/src/plugin.ts
  • packages/kit/test/generate-types.spec.ts
  • packages/kit/src/resolve.ts
  • packages/webpack/src/presets/base.ts
  • packages/kit/src/module/install.ts
  • packages/nuxt/src/core/external-config-files.ts
  • packages/nuxt/src/core/utils/types.ts
  • packages/schema/src/config/vite.ts
📚 Learning: 2024-12-12T12:36:34.871Z
Learnt from: huang-julien
Repo: nuxt/nuxt PR: 29366
File: packages/nuxt/src/app/components/nuxt-root.vue:16-19
Timestamp: 2024-12-12T12:36:34.871Z
Learning: In `packages/nuxt/src/app/components/nuxt-root.vue`, when optimizing bundle size by conditionally importing components based on route metadata, prefer using inline conditional imports like:

```js
const IsolatedPage = route?.meta?.isolate ? defineAsyncComponent(() => import('#build/isolated-page.mjs')) : null
```

instead of wrapping the import in a computed property or importing the component unconditionally.

Applied to files:

  • packages/nuxt/test/page-metadata.test.ts
📚 Learning: 2025-11-25T11:42:16.132Z
Learnt from: CR
Repo: nuxt/nuxt PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-11-25T11:42:16.132Z
Learning: Applies to **/*.{test,spec}.{ts,tsx,js} : Write unit tests for core functionality using `vitest`

Applied to files:

  • packages/nuxt/test/page-metadata.test.ts
  • packages/kit/test/generate-types.spec.ts
  • packages/schema/src/config/vite.ts
📚 Learning: 2025-11-25T11:42:16.132Z
Learnt from: CR
Repo: nuxt/nuxt PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-11-25T11:42:16.132Z
Learning: Applies to **/e2e/**/*.{ts,tsx,js} : Write end-to-end tests using Playwright and `nuxt/test-utils`

Applied to files:

  • packages/nuxt/test/page-metadata.test.ts
📚 Learning: 2025-11-25T11:42:16.132Z
Learnt from: CR
Repo: nuxt/nuxt PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-11-25T11:42:16.132Z
Learning: Applies to **/*.{ts,tsx,js,jsx,vue} : Remove code that is not used or needed

Applied to files:

  • packages/nuxt/test/page-metadata.test.ts
  • packages/kit/src/module/install.ts
  • packages/nuxt/src/core/utils/types.ts
  • packages/schema/src/config/vite.ts
📚 Learning: 2025-11-25T11:42:16.132Z
Learnt from: CR
Repo: nuxt/nuxt PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-11-25T11:42:16.132Z
Learning: Applies to **/*.{ts,tsx,vue} : Follow standard TypeScript conventions and best practices

Applied to files:

  • packages/nuxt/test/page-metadata.test.ts
  • packages/kit/src/internal/esm.ts
  • packages/kit/src/plugin.ts
  • packages/kit/test/generate-types.spec.ts
  • packages/kit/src/resolve.ts
  • packages/kit/src/module/install.ts
  • packages/nuxt/src/core/utils/types.ts
  • packages/schema/src/config/vite.ts
📚 Learning: 2025-11-25T11:42:16.132Z
Learnt from: CR
Repo: nuxt/nuxt PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-11-25T11:42:16.132Z
Learning: Applies to **/*.{ts,tsx,js,jsx,vue} : Use error handling patterns consistently

Applied to files:

  • packages/nuxt/test/page-metadata.test.ts
  • packages/kit/src/module/install.ts
  • packages/nuxt/src/core/utils/types.ts
📚 Learning: 2024-11-05T15:22:54.759Z
Learnt from: GalacticHypernova
Repo: nuxt/nuxt PR: 26468
File: packages/nuxt/src/components/plugins/loader.ts:24-24
Timestamp: 2024-11-05T15:22:54.759Z
Learning: In `packages/nuxt/src/components/plugins/loader.ts`, the references to `resolve` and `distDir` are legacy code from before Nuxt used the new unplugin VFS and will be removed.

Applied to files:

  • packages/kit/src/plugin.ts
  • packages/kit/test/generate-types.spec.ts
  • packages/kit/src/resolve.ts
  • packages/webpack/src/presets/base.ts
  • packages/kit/src/module/install.ts
  • packages/nuxt/src/core/external-config-files.ts
  • packages/nuxt/src/core/utils/types.ts
  • packages/schema/src/config/vite.ts
📚 Learning: 2025-11-25T11:42:16.132Z
Learnt from: CR
Repo: nuxt/nuxt PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-11-25T11:42:16.132Z
Learning: Applies to **/*.vue : Use `<script setup lang="ts">` and the composition API when creating Vue components

Applied to files:

  • packages/kit/src/module/install.ts
  • packages/nuxt/src/core/utils/types.ts
  • packages/schema/src/config/vite.ts
📚 Learning: 2025-11-25T11:42:16.132Z
Learnt from: CR
Repo: nuxt/nuxt PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-11-25T11:42:16.132Z
Learning: Applies to **/*.{ts,tsx,js,jsx,vue} : Use clear, descriptive variable and function names

Applied to files:

  • packages/nuxt/src/core/utils/types.ts
🧬 Code graph analysis (1)
packages/kit/src/plugin.ts (1)
packages/kit/src/context.ts (1)
  • tryUseNuxt (51-54)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: build
  • GitHub Check: code
🔇 Additional comments (8)
packages/kit/src/module/install.ts (1)

223-224: Module resolution extensions broadened consistently

The extended extensions lists here look coherent and will allow modules shipped as .mts, .cts, .tsx or .jsx to be resolved both via resolveModuleWithOptions and loadNuxtModuleInstance. Keeping the two arrays in sync is good; no issues from this change as-is.

Also applies to: 260-261

packages/kit/test/generate-types.spec.ts (1)

26-27: Mock extensions kept in sync with runtime defaults

Updating the test mockNuxt.options.extensions to cover .cjs, .tsx/.jsx and .mts/.cts keeps type-generation tests aligned with the actual resolver behaviour. Looks good.

packages/webpack/src/presets/base.ts (1)

149-155: Webpack resolve extensions updated to cover JS/TS variants

The new resolve.extensions set for webpack sensibly adds .cjs, .mts and .cts and places .js before .mjs, bringing it closer in line with the Vite configuration while still allowing user overrides via ctx.config.resolve. No issues spotted.

packages/schema/src/config/vite.ts (1)

28-29: Vite resolver extensions aligned with broader Nuxt support

The updated vite.resolve.extensions now matches the extended JS/TS landscape (.cjs, .mts, .cts, TSX/JSX) and aligns ordering with the webpack preset and external-config checks. This should make cross-tooling resolution more predictable.

packages/nuxt/test/page-metadata.test.ts (1)

21-28: Tests now cover CTS/MTS page files for metadata extraction

Adding 'cts' and 'mts' to the extension loop usefully extends coverage so getRouteMeta is asserted to work for those TS module variants as well, in line with the new resolver support elsewhere. Looks good.

packages/kit/src/internal/esm.ts (2)

12-12: LGTM! JSX/TSX support addition improves module resolution.

The extension list now includes .jsx and .tsx, broadening support for JSX-based modules. The JSDoc comment correctly reflects the implementation.

Note: The PR title mentions adding .mts, but .mts and .cts were already present. The actual changes add .jsx and reorder the extension priority.

Also applies to: 41-41


41-41: No action required. The file and function are new additions, not reorderings of existing code. The extension array ['.js', '.mjs', '.ts', '.cjs', '.tsx', '.jsx', '.mts', '.cts'] is the default for the newly introduced resolveModule() function and does not represent a breaking change in existing resolution behaviour.

Likely an incorrect or invalid review comment.

packages/kit/src/plugin.ts (1)

37-37: LGTM! Extension list is now consistent with packages/kit/src/internal/esm.ts.

The fallback extension array now matches the default extensions used in resolveModule, ensuring consistent module resolution behaviour across the kit. The addition of .jsx support and reordering aligns with the broader changes in this PR.

Note: The same extension reordering implications noted in packages/kit/src/internal/esm.ts apply here as well.

# Conflicts:
#	packages/nuxt/src/core/external-config-files.ts
#	packages/nuxt/src/core/utils/types.ts
@danielroe

Copy link
Copy Markdown
Member

@danielroe danielroe changed the title fix: add .mts file extension in resolver default fix(kit,nuxt,rspack,schema,webpack): add .mts file extension in resolver Jul 19, 2026
@danielroe
danielroe enabled auto-merge July 19, 2026 10:56
@danielroe
danielroe added this pull request to the merge queue Jul 19, 2026
Merged via the queue into nuxt:main with commit d6c737a Jul 19, 2026
29 checks passed
@github-actions github-actions Bot mentioned this pull request Jul 19, 2026
2 of 5 tasks
danielroe added a commit that referenced this pull request Jul 20, 2026
…olver (#33845)

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Alexander Lichter <github@lichter.io>
Co-authored-by: Daniel Roe <daniel@roe.dev>
(cherry picked from commit d6c737a)
@github-actions github-actions Bot mentioned this pull request Jul 20, 2026
danielroe added a commit that referenced this pull request Jul 20, 2026
…olver (#33845)

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Alexander Lichter <github@lichter.io>
Co-authored-by: Daniel Roe <daniel@roe.dev>
(cherry picked from commit d6c737a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4.x 🐛 bug Something isn't working as expected

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants