Skip to content

Conversation

@OrbisK
Copy link
Member

@OrbisK OrbisK commented Dec 10, 2025

📚 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

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@coderabbitai
Copy link

coderabbitai bot commented Dec 10, 2025

Walkthrough

This PR expands and reorders the sets of file extensions used across multiple resolver and build configurations. Changes add support for .js, .jsx, .tsx, .cjs, .mts and .cts (and reorder existing entries) in resolver defaults and tests (packages/schema, kit, nuxt, webpack, vite, tests). It also fixes the webpack external-config check to use '.coffee' with a leading dot. No control flow, error handling or exported/public API signatures were changed.

Possibly related PRs

  • PR #29799 — Modifies module resolution logic in module/install.ts; closely related to this PR's changes to resolution extensions.
  • PR #32857 — Adjusts resolve.ts handling and extension normalization; directly related to the expanded default extension list in resolve.ts.
  • PR #29955 — Changes resolution behavior in module/install.ts (loadNuxtModuleInstance/resolve paths); overlaps with this PR's extension/order updates.

Pre-merge checks and finishing touches

❌ 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%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding .mts file extension support to resolver defaults across multiple files in the codebase.
Description check ✅ Passed The description references a related change and explains the motivation (.mts was missing from the resolver), which aligns with the changeset that adds .mts and other extensions across multiple resolver configuration files.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

✨ Issue Enrichment is now available for GitHub issues!

CodeRabbit can now help you manage issues more effectively:

  • Duplicate Detection — Identify similar or duplicate issues
  • Related Issues & PRs — Find relevant issues and PR's from your repository
  • Suggested Assignees — Find the best person to work on the issue
  • Implementation Planning — Generate detailed coding plans for engineers and agents
Disable automatic issue enrichment

To disable automatic issue enrichment, add the following to your .coderabbit.yaml:

issue_enrichment:
  auto_enrich:
    enabled: false

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 and usage tips.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Dec 10, 2025

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: 84b98fb

@codspeed-hq
Copy link

codspeed-hq bot commented Dec 10, 2025

CodSpeed Performance Report

Merging #33845 will not alter performance

Comparing OrbisK:fix/extensions-mts (ab9a613) with main (ac906ce)1

Summary

✅ 10 untouched

Footnotes

  1. No successful run was found on main (86d67b2) during the generation of this report, so ac906ce was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

Co-authored-by: Alexander Lichter <[email protected]>
extensions: {
$resolve: (val): string[] => {
const extensions = ['.js', '.jsx', '.mjs', '.ts', '.tsx', '.vue']
const extensions = ['.js', '.jsx', '.mjs', '.ts', '.tsx', '.mts', '.vue']
Copy link
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

@coderabbitai coderabbitai bot left a comment

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants