fix: exclude prebuilt dist from swc and react-refresh loaders - #12434
Merged
Conversation
`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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
pnpm run devfailed withModule parse failed: 'import' and 'export' may appear only with 'sourceType: module'onpackages/spl-name-service/dist/*.js(the vendored@bonfida/spl-name-service, prebuilt CJS).include: packages/also matched the prebuilt dist files, running them through swc.importpreamble to each file it processes — and it injects its loader vianormalModuleFactory.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:/dist/from the TS/swc ruleexclude: [/node_modules/i, /dist/]to the react-refresh plugin (webpack & rspack variants), keeping the plugin's defaultnode_modulesexclusionVerification
pnpm start(webpack dev):compiled successfullyfor both the initial build and incremental rebuilds; previously it failed with the 2 module parse errors.