Skip to content

[Rspack][SWC] fix: add support for swc.config.ts in meteor 3.4#14150

Merged
nachocodoner merged 4 commits intometeor:swc-config-improvementsfrom
sanki92:fix-issue-14033-swc-config-ts
Mar 17, 2026
Merged

[Rspack][SWC] fix: add support for swc.config.ts in meteor 3.4#14150
nachocodoner merged 4 commits intometeor:swc-config-improvementsfrom
sanki92:fix-issue-14033-swc-config-ts

Conversation

@sanki92
Copy link
Copy Markdown
Contributor

@sanki92 sanki92 commented Feb 18, 2026

Problem

Meteor's Rspack integration currently only supports .swcrc and swc.config.js for SWC transpiler configuration. TS developers can't use swc.config.ts for type-safe configs, which is a common pattern in modern TS projects.

Solution

Extended the SWC config loader to support .ts files:

• Added TS file handling with automatic transpilation (esbuild primary, regex fallback)
• Maintains priority order: .swcrc > swc.config.js > swc.config.ts
• Added swc.config.ts to Rspack cache dependencies for proper invalidation

Changes Made

npm-packages/meteor-rspack/lib/swc.js

• Extended getMeteorAppSwcrc() to handle .ts extensions
• Added TS transpilation with esbuild (falls back to regex if unavailable)
• Strips TS syntax: imports, types, interfaces, decorators
• Converts ES modules to CommonJS
• Updated getMeteorAppSwcConfig() to check for all three config types

npm-packages/meteor-rspack/rspack.config.js

• Added swc.config.ts path detection
• Included in build dependencies for cache invalidation

Verification

Tested with Meteor TS app:

• Only swc.config.ts present - loads correctly
• Both swc.config.js and swc.config.ts present - swc.config.js takes priority
• All three configs present - .swcrc takes priority

Example swc.config.ts:

import type { Config } from '@swc/core';

const config: Config = {
  jsc: {
    target: 'es2020',
    parser: {
      syntax: 'typescript',
      tsx: true,
      decorators: true,
    },
  },
  sourceMaps: true,
};

export default config;

Fixes #14033

@netlify
Copy link
Copy Markdown

netlify bot commented Feb 18, 2026

Deploy Preview for v3-migration-docs canceled.

Name Link
🔨 Latest commit 48685ff
🔍 Latest deploy log https://app.netlify.com/projects/v3-migration-docs/deploys/6995b7003f67af000893c16b

@netlify
Copy link
Copy Markdown

netlify bot commented Feb 18, 2026

Deploy Preview for v3-meteor-api-docs ready!

Name Link
🔨 Latest commit 1ac166f
🔍 Latest deploy log https://app.netlify.com/projects/v3-meteor-api-docs/deploys/69b96642af136e00082d7888
😎 Deploy Preview https://deploy-preview-14150.docs-online.meteor.com
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Copy Markdown
Member

@nachocodoner nachocodoner left a comment

Choose a reason for hiding this comment

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

In packages/babel-compiler/babel-compiler.js, there is also code around .swcrc/swc.config.js file usage. This is used by the Meteor bundler with modern:true in Meteor 3.3, not only by the Rspack integration that came later. It should also support swc.config.ts in the Meteor bundler, along with Meteor Rspack that you already cover.

Again, thanks to this proactivity on helping us to fix these issues.


if (file.endsWith('.ts')) {
try {
const esbuild = require('esbuild');
Copy link
Copy Markdown
Member

@nachocodoner nachocodoner Feb 18, 2026

Choose a reason for hiding this comment

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

why do you use esbuild here?

We already benefit from @swc/core (builtin in Rspack), why don't use swc here to transform this file?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ahh you're right, my bad, didn't think to check what Rspack already had bundled. I was focused on getting the TS parsing working and just reached for esbuild. Makes way more sense to use what's already there.

And yeah, completely missed that babel-compiler needed this too. I was only testing through the Rspack path. Fixed now, but let me know if you see anything else.

@nachocodoner nachocodoner added this to the Release 3.4.1 milestone Feb 18, 2026
@nachocodoner nachocodoner changed the base branch from devel to release-3.4.1 February 18, 2026 13:08
@nachocodoner nachocodoner changed the title fix: add support for swc.config.ts in meteor 3.4 [Rspack][SWC] fix: add support for swc.config.ts in meteor 3.4 Feb 18, 2026
"author": "Ben Newman <ben@meteor.com>",
"description": "Stub implementations of Node built-in modules, a la Browserify",
"version": "1.2.24",
"version": "1.2.26",
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.

Why meteor-node-stubs was bumped here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

My branch accidentally included those commits because I branched from devel, and when you changed the PR base to release-3.4.1, it picked up the extra commits.

Just cleaned it up, Should be good now, Sorry for the inconvenience :)

@sanki92 sanki92 force-pushed the fix-issue-14033-swc-config-ts branch from 92de319 to 134b28d Compare February 20, 2026 05:28
@sanki92
Copy link
Copy Markdown
Contributor Author

sanki92 commented Mar 3, 2026

Hey @nachocodoner, caught one more issue while re-reviewing, the SWC transform had module: { type: 'commonjs' }, which converts export default config into exports.default = config. That means the vm sandbox wraps the config in { default: config }, so the user's SWC options would silently get lost during merge.

Fixed by removing the module option, SWC now only strips TypeScript syntax and keeps export default as-is, which the existing handler already converts to module.exports =. Also added a __esModule safety guard in case SWC's default module behavior ever changes. Applied to both swc.js and babel-compiler.js.

Please take a look and lmk if you see anything else that needs adjustment.

Copy link
Copy Markdown
Member

@nachocodoner nachocodoner left a comment

Choose a reason for hiding this comment

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

Approved and merging it, @sanki92. I applied the last round of tweaks on your changes on this PR, #14233. Feel free to check them out, but there are just to provide more docs, E2E test and fix an issue I found on my way to validate your work.

Thanks again for this contribution. Your proactivity with Meteor contributions is great to see. Good work!

@nachocodoner nachocodoner changed the base branch from release-3.4.1 to swc-config-improvements March 17, 2026 16:34
@nachocodoner nachocodoner merged commit fbe1ada into meteor:swc-config-improvements Mar 17, 2026
34 of 35 checks passed
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.

[Meteor 3.4] Cant use swc.config.ts

2 participants