Skip to content

fix: exclude prebuilt dist from swc and react-refresh loaders - #12434

Merged
guanbinrui merged 1 commit into
developfrom
fix/dev-spl-name-service-dist-refresh
Sep 5, 2026
Merged

fix: exclude prebuilt dist from swc and react-refresh loaders#12434
guanbinrui merged 1 commit into
developfrom
fix/dev-spl-name-service-dist-refresh

Conversation

@swkatmask

Copy link
Copy Markdown
Contributor

Summary

  • pnpm run dev failed with Module parse failed: 'import' and 'export' may appear only with 'sourceType: module' on packages/spl-name-service/dist/*.js (the vendored @bonfida/spl-name-service, prebuilt CJS).
  • Root cause 1: the TS/swc rule's include: packages/ also matched the prebuilt dist files, running them through swc.
  • Root cause 2: the react-refresh plugin prepends an ESM import preamble to each file it processes — and it injects its loader via normalModuleFactory.hooks.afterResolve, outside webpack module rules, so a rule-level exclude alone doesn't stop it. Mixing that preamble into CJS breaks webpack's module detection.

Changes

  • packages/mask/.webpack/config.ts:
    • exclude /dist/ from the TS/swc rule
    • add exclude: [/node_modules/i, /dist/] to the react-refresh plugin (webpack & rspack variants), keeping the plugin's default node_modules exclusion

Verification

  • pnpm start (webpack dev): compiled successfully for both the initial build and incremental rebuilds; previously it failed with the 2 module parse errors.

Note: node_modules must stay in the plugin exclude — overriding exclude alone replaces the plugin's default /node_modules/i and floods the build with ~17k errors.

`pnpm run dev` failed with "Module parse failed: 'import' and 'export'
may appear only with 'sourceType: module'" on the vendored
@bonfida/spl-name-service dist files.

The TS/swc rule includes all of packages/, so it also matched the
prebuilt CJS dist. With HMR on, the react-refresh plugin prepends an
ESM import preamble to every file it processes (injected via
normalModuleFactory hooks, outside module rules), mixing ESM into CJS
which webpack cannot parse.

- exclude dist/ from the TS/swc rule
- exclude dist/ (plus the plugin's default node_modules exclusion) from
  the react-refresh plugin
@guanbinrui
guanbinrui merged commit 9f24c9e into develop Sep 5, 2026
11 checks passed
@guanbinrui
guanbinrui deleted the fix/dev-spl-name-service-dist-refresh branch September 5, 2026 15:11
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.

2 participants