Skip to content

Commit 9a5fef9

Browse files
feat: support tsx as a fallback loader for TypeScript and JSX configs (#4796)
* feat: support tsx as a fallback loader for TypeScript configs Register `tsx/cjs` manually when the loaders known to `interpret` are unavailable. It cannot go through `interpret`/`rechoir`: the `tsx/cjs` entry point exists only in the package's `exports` map, which `rechoir`'s resolver (legacy `resolve@1.x`) does not support, so it is resolved with `createRequire` from the configuration file's location and required directly, installing its require hook. The loaders listed in `interpret` keep priority; `tsx` is tried only after all of them have failed. For `.mts`, which has no `interpret` entry at all, `tsx` is registered best-effort and the original error reporting is preserved when it is missing. When nothing works, the `tsx` resolution failure is appended to the existing loader failure list before "Please install one of them". The fixture shadows the `interpret` loaders with generated throwing stubs (kept out of the repository — `test/**/node_modules` is already ignored) so the tests exercise the real `tsx` package from the root dev dependencies for both `.ts` and `.mts` configurations. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Hv8piVkEGYdWzWoWCtMcif * feat: extend the tsx fallback loader to .jsx configurations `tsx/cjs` also installs a require hook for `.jsx` (esbuild transform, including `@jsx` pragma support), so offer it as a fallback there too when the `interpret` loaders (`@babel/register`, `sucrase`) are not installed. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Hv8piVkEGYdWzWoWCtMcif * fix: address Copilot review feedback - Normalize non-Error throws in the tsx registration so the error-reporting path can rely on `.message`. - Fix the pre-existing "Unable load" typo ("Unable to load"). - Cover `.cts` (special-cased extension mapping) and `.tsx` (types and JSX together) in the fixture, alongside `.ts`, `.mts` and `.jsx`. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Hv8piVkEGYdWzWoWCtMcif --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 6cafa00 commit 9a5fef9

13 files changed

Lines changed: 747 additions & 8 deletions

File tree

.changeset/tsx-config-loader.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"webpack-cli": minor
3+
---
4+
5+
Support `tsx` as a fallback loader for TypeScript and JSX configuration files (`.ts`, `.tsx`, `.cts`, `.mts` and `.jsx`), used when none of the loaders known to `interpret` (such as `ts-node`) are installed.

eslint.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export default defineConfig([
1616
"test/build/config-format/esm-require-await/webpack.config.js",
1717
"test/configtest/with-config-path/syntax-error.config.js",
1818
"test/build/config-format/auto/webpack.config.js",
19+
"test/build/config-format/typescript-tsx/webpack.config.jsx",
1920
]),
2021
{
2122
extends: [config],

0 commit comments

Comments
 (0)