Skip to content

fix: prevent UnexpectedBuildError misclassification and add SWC loader for TS/JSX/CJS - #100

Merged
pastelsky merged 4 commits into
masterfrom
codex/stale-while-revalidate-badge
Aug 10, 2026
Merged

fix: prevent UnexpectedBuildError misclassification and add SWC loader for TS/JSX/CJS#100
pastelsky merged 4 commits into
masterfrom
codex/stale-while-revalidate-badge

Conversation

@pastelsky

Copy link
Copy Markdown
Owner

Summary

Fixes a critical bug in _parseMissingModules where non-missing-module compilation errors (such as Rspack/SWC syntax parse errors) were blindly passed to _parseMissingModules, causing them to fail regex matching and crash with an UnexpectedBuildError ("Expected to find a file path in the module not found error...").

Additionally, adds .jsx, .ts, .tsx, .cjs to Rspack's resolve.extensions and configures builtin:swc-loader for /\.(js|mjs|jsx|ts|tsx|cjs)$/ so packages publishing raw TypeScript or JSX compile cleanly.

Before vs. After Comparison

Example 1: Non-missing-module compilation error (e.g. slim-ui)

  • Before:
    getPackageStats('slim-ui') threw an unhandled crash:

    {
      "name": "UnexpectedBuildError",
      "originalError": "Expected to find a file path in the module not found error, but found none. Regex for this might be out of date."
    }

    This misclassified syntax errors as server unexpected errors (500s).

  • After:
    getPackageStats('slim-ui') cleanly catches and returns structured compilation error details:

    {
      "name": "BuildError",
      "originalError": [
        {
          "message": "Module parse failed: JavaScript parse error: Expression expected in <RadioGroup.vue>",
          "code": "ModuleParseError"
        }
      ]
    }

Example 2: Published TypeScript / JSX / ES2022 syntax

  • Before: Rspack default parser failed without a loader when encountering TypeScript interfaces or JSX elements in published NPM packages.
  • After: builtin:swc-loader transpiles TS/JSX/ES2022+ features down to ES2017 seamlessly.

Testing & Verification

  • Added a unit test in tests/fast/build.utils.test.ts verifying _parseMissingModules handles non-missing-module compilation errors cleanly.
  • corepack yarn test: 33/33 tests passing.
  • corepack yarn check: 0 errors (TypeScript type check passed, Oxlint passed, Prettier format checked).
  • Created changeset .changeset/fix-module-parse-errors.md.

@pastelsky
pastelsky force-pushed the codex/stale-while-revalidate-badge branch from 81912ba to 999f01d Compare August 10, 2026 13:21
@pastelsky
pastelsky merged commit 7864791 into master Aug 10, 2026
3 checks passed
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