Fix virtual loader resolution under enhanced-resolve >= 5.21 - #77
Merged
Conversation
The virtual HTML/style/script loader modules were registered with keys relative to the webpack compiler context, landing under the consumer app's node_modules. But config.ts imports them through the bare `@studiometa/playground/<name>-loader.js` specifiers, which webpack resolves via the package's `"./*": "./*"` exports entry to the package's real on-disk root — a different path. This only worked while enhanced-resolve <= 5.20 fell back to legacy resolution for a matched-but-missing exports target. enhanced-resolve >= 5.21 (webpack/enhanced-resolve#399) makes that a hard error, so consumer builds on webpack 5.109+ failed with "Package path ./html-loader.js is exported from package ... but no valid target file was found". Write the virtual files at the package's resolved root so the exports-field target exists on disk. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HKLcgvaDcjK9ohA3fg7Ssq
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HKLcgvaDcjK9ohA3fg7Ssq
Deploying studiometa-playground with
|
| Latest commit: |
7bf8fbd
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://8d575384.studiometa-playground.pages.dev |
| Branch Preview URL: | https://fix-virtual-loader-exports-r.studiometa-playground.pages.dev |
|
Size Change: +87 B (+0.16%) Total Size: 54.2 kB 📦 View Changed
ℹ️ View Unchanged
|
Codecov Report❌ Patch coverage is
❌ Your patch check has failed because the patch coverage (0.00%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #77 +/- ##
==========================================
- Coverage 34.12% 34.06% -0.07%
==========================================
Files 55 55
Lines 1131 1133 +2
Branches 231 231
==========================================
Hits 386 386
- Misses 717 719 +2
Partials 28 28
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Problem
Consumer builds on webpack 5.109+ (enhanced-resolve 5.24.5) fail with:
(and the same for
style-loader.jsandscript-loader.js).Root cause
PlaygroundLoadersPluginregisters the three virtual loader modules withwebpack-virtual-modulesusing keys relative to the compiler context:webpack-virtual-modulesjoins each relative key againstcompiler.context(the consumer app's build context), so the virtual files land under<consumer-context>/node_modules/@studiometa/playground/.But
config.tsimports the bare specifiers@studiometa/playground/<name>-loader.js. Webpack resolves those through the package's"./*": "./*"exports entry to the package's real resolved root — a different path than where the virtual files were written.This used to work only by accident: enhanced-resolve <= 5.20 fell back to legacy resolution when an
exportstarget was matched but missing on disk. enhanced-resolve >= 5.21 (webpack/enhanced-resolve#399, #400) changed that matched-but-missing case into a hard error. After webpack bumped to 5.109.x, the fallback disappeared and the loaders no longer resolve.Fix
Write the virtual loaders at the package's actual resolved on-disk root (absolute path via
createRequire(import.meta.url).resolve('@studiometa/playground/package.json')) instead of a path relative to the compiler context, so theexports-field target resolves to a real (virtual) file.Validation
npm run build:esbuildandnpm run build:typessucceed, types check clean.oxlintreports 0 warnings / 0 errors on the changed file.vitestsuite: 153 tests pass.@studiometa/ui's playgroundplay:build(webpack 5.109.x / enhanced-resolve 5.24.5) and the build that previously errored now completes.🤖 Generated with Claude Code
https://claude.ai/code/session_01HKLcgvaDcjK9ohA3fg7Ssq