Skip to content

fix: esm module 99 and cjs module 100#354

Open
birkskyum wants to merge 1 commit intoTanStack:mainfrom
birkskyum:set-99-for-esm-and-100-for-cjs
Open

fix: esm module 99 and cjs module 100#354
birkskyum wants to merge 1 commit intoTanStack:mainfrom
birkskyum:set-99-for-esm-and-100-for-cjs

Conversation

@birkskyum
Copy link
Member

@birkskyum birkskyum commented Mar 15, 2026

Remake of:

@lachlancollins I think we have to stay on:

CJS - module 100
ESM - module 99

When i bump vite-config to 0.5.1 in tanstack/router, I get errors with import.meta otherwise.

There is a patch in this PR:

Summary by CodeRabbit

  • Bug Fixes
    • Fixed module configuration for ESM and CJS builds to ensure proper module declaration generation during the build process.

@changeset-bot
Copy link

changeset-bot bot commented Mar 15, 2026

🦋 Changeset detected

Latest commit: 8405e08

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@tanstack/vite-config Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai
Copy link

coderabbitai bot commented Mar 15, 2026

📝 Walkthrough

Walkthrough

A changeset and configuration update for the @tanstack/vite-config package. The TypeScript compiler module configuration in the dts plugin is updated from NodeNext (199) to ESNext (99) for ESM builds and CommonJS/Node16 (100) for CJS builds, with a corresponding patch-level changeset document.

Changes

Cohort / File(s) Summary
Module Compilation Configuration
.changeset/cool-needles-hear.md, packages/vite-config/src/index.ts
Updates TypeScript dts plugin module configuration from NodeNext to ESNext (ESM) and CommonJS/Node16 (CJS) targets. Changeset documents this as a patch-level fix for esm and cjs module handling.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 Hop, hop—the modules dance anew,
From NextNode down to ninety-two,
ESM and CommonJS align,
A patchy fix makes code design shine!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is minimal and lacks the required sections from the template, including a detailed 'Changes' section, checklist items, and explicit release impact statement. Add the missing sections: expand the 'Changes' section with detailed motivation, check the required items in the checklist, and clearly indicate if a changeset was generated for the release impact.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: updating TypeScript compiler module options to use ESM module 99 and CJS module 100.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
📝 Coding Plan
  • Generate coding plan for human review comments

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.

@nx-cloud
Copy link

nx-cloud bot commented Mar 15, 2026

View your CI Pipeline Execution ↗ for commit 8405e08

Command Status Duration Result
nx affected --targets=test:sherif,test:docs,tes... ✅ Succeeded 15s View ↗
nx run-many --target=build ✅ Succeeded 7s View ↗

☁️ Nx Cloud last updated this comment at 2026-03-15 17:11:48 UTC

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 15, 2026

npm i https://pkg.pr.new/@tanstack/eslint-config@354
npm i https://pkg.pr.new/@tanstack/publish-config@354
npm i https://pkg.pr.new/@tanstack/typedoc-config@354
npm i https://pkg.pr.new/@tanstack/vite-config@354

commit: 8405e08

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.

🧹 Nitpick comments (1)
packages/vite-config/src/index.ts (1)

60-60: Use named constants for TypeScript module kinds and correct the Node16 label.

Lines 60 and 86 use raw numeric literals (99, 100) instead of named constants, and the comment on line 86 labels 100 as "CommonJS - Node16", which is misleading. Node16 models Node's dual ESM/CommonJS system where TypeScript decides per-file emission based on file extension and package.json—it is not equivalent to CommonJS. Use explicit named constants and label as Node16 to improve maintainability and prevent confusion.

♻️ Suggested refactor
+const DTS_MODULE_KIND_ESM = 99 // TypeScript ModuleKind.ESNext
+const DTS_MODULE_KIND_NODE16 = 100 // TypeScript ModuleKind.Node16
+
 export const tanstackViteConfig = (options: Options): UserConfig => {
@@
         compilerOptions: {
-          module: 99, // ESNext
+          module: DTS_MODULE_KIND_ESM,
           declarationMap: false,
         },
@@
             compilerOptions: {
-              module: 100, // CommonJS - Node16
+              module: DTS_MODULE_KIND_NODE16,
               declarationMap: false,
             },

Also applies to: 86-86

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/vite-config/src/index.ts` at line 60, Replace the raw numeric module
kind literals with TypeScript's named enum members: change occurrences of
"module: 99" to "module: ts.ModuleKind.ESNext" and "module: 100" to "module:
ts.ModuleKind.Node16", and update the comment that currently says "CommonJS -
Node16" to just "Node16"; ensure the file imports or references the TypeScript
namespace (e.g., import * as ts from 'typescript') so ts.ModuleKind is available
and use these enum names in the configuration object(s) where "module: 99" and
"module: 100" appear.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/vite-config/src/index.ts`:
- Line 60: Replace the raw numeric module kind literals with TypeScript's named
enum members: change occurrences of "module: 99" to "module:
ts.ModuleKind.ESNext" and "module: 100" to "module: ts.ModuleKind.Node16", and
update the comment that currently says "CommonJS - Node16" to just "Node16";
ensure the file imports or references the TypeScript namespace (e.g., import *
as ts from 'typescript') so ts.ModuleKind is available and use these enum names
in the configuration object(s) where "module: 99" and "module: 100" appear.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4be906f1-b7b5-42fe-a3a4-363ee6480c35

📥 Commits

Reviewing files that changed from the base of the PR and between f35fa37 and 8405e08.

📒 Files selected for processing (2)
  • .changeset/cool-needles-hear.md
  • packages/vite-config/src/index.ts

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.

1 participant