Skip to content

Fix declaration chunk imports referencing non-existent .js files - #76

Merged
titouanmathis merged 2 commits into
mainfrom
fix/dts-chunk-import-extension
Aug 6, 2026
Merged

Fix declaration chunk imports referencing non-existent .js files#76
titouanmathis merged 2 commits into
mainfrom
fix/dts-chunk-import-extension

Conversation

@titouanmathis

Copy link
Copy Markdown
Contributor

Problem

When a self-hosted dependency code-splits, its emitted declaration files reference type chunks that don't exist on disk, so the editor's LSP fails to resolve types.

rolldown-plugin-dts writes the relative imports between declaration chunks with a .js extension (mirroring the JS module graph — the on-disk convention where ./foo.js resolves to a sibling ./foo.d.ts). But the declaration chunks are content-hashed independently from the JS chunks. So for @studiometa/ui:

Action.d.ts        →  import … from "./Action-Bt0NVlQH.js"   ← dts hash
Action-Bt0NVlQH.d.ts   (exists)
Action-CJcyZH91.js     (the real JS chunk — different hash!)

Action-Bt0NVlQH.js never exists. Served over HTTP the LSP fetches that literal URL, 404s, and type resolution breaks for every code-split subpath.

Fix

The specifier already carries the declaration chunk's own basename + hash — only the extension is wrong. In emitBundleChunks, rewrite relative .js specifiers to .d.ts inside emitted .d.ts chunks (from "./x.js", import("./x.js"), export … from "./x.js"). Bare specifiers (@studiometa/js-toolkit/utils) and the JS chunks themselves are untouched.

Verified against a real @studiometa/ui multi-entry build: before, 4 relative type imports pointed at non-existent .js files; after, all 4 resolve to existing .d.ts chunks.

Tests

  • New unit test on the emit harness: a declaration chunk importing ./Foo-<hash>.js (static, re-export, and dynamic import()) is emitted with .d.ts; no relative .js specifier remains; bare specifiers and the JS entry are unchanged.
  • 153 tests pass; lint, type-check, and build clean.

Release

Bugfix — would ship as 0.3.13. Not published here.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Botz34NmFLdgRgm2QJpKkZ

titouanmathis and others added 2 commits August 6, 2026 10:21
rolldown-plugin-dts writes the relative imports between declaration chunks
with a `.js` extension (mirroring the JS module graph). But the declaration
chunks are content-hashed independently from the JS chunks, so the referenced
`./Foo-<dtsHash>.js` never exists on disk — only `./Foo-<dtsHash>.d.ts` does,
because the JS chunk carries a different hash. Served over HTTP, the editor's
LSP fetches the literal `.js` specifier, 404s, and type resolution breaks for
any code-split subpath.

The specifier already carries the declaration chunk's own basename and hash;
only the extension is wrong. Swap `.js` -> `.d.ts` on relative specifiers in
emitted `.d.ts` chunks so every type import resolves to a real file. Bare
specifiers (e.g. @studiometa/js-toolkit/utils) are left untouched.

Co-authored-by: Claude <claude@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Botz34NmFLdgRgm2QJpKkZ
Co-authored-by: Claude <claude@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Botz34NmFLdgRgm2QJpKkZ
@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown

Size Change: +543 B (+1.01%)

Total Size: 54.1 kB

📦 View Changed
Filename Size Change
packages/playground/dist/lib/plugins/PlaygroundDependenciesPlugin.js 4.36 kB +543 B (+14.23%) ⚠️
ℹ️ View Unchanged
Filename Size
packages/playground-preview/dist/element.js 10 kB
packages/playground-preview/dist/index.js 10 kB
packages/playground/dist/front/css/app.css 4.26 kB
packages/playground/dist/front/js/app.js 139 B
packages/playground/dist/front/js/components/Editor.js 929 B
packages/playground/dist/front/js/components/Editors.js 265 B
packages/playground/dist/front/js/components/EditorVisibility.js 343 B
packages/playground/dist/front/js/components/HeaderSwitcher.js 436 B
packages/playground/dist/front/js/components/HtmlEditor.js 748 B
packages/playground/dist/front/js/components/Iframe.js 1.74 kB
packages/playground/dist/front/js/components/IframeReloader.js 182 B
packages/playground/dist/front/js/components/LayoutReactive.js 616 B
packages/playground/dist/front/js/components/LayoutSwitcher.js 341 B
packages/playground/dist/front/js/components/Playground.js 1.14 kB
packages/playground/dist/front/js/components/Resizable.js 992 B
packages/playground/dist/front/js/components/ResizableCursor.js 298 B
packages/playground/dist/front/js/components/ResizableSync.js 512 B
packages/playground/dist/front/js/components/ScriptEditor.js 520 B
packages/playground/dist/front/js/components/StyleEditor.js 247 B
packages/playground/dist/front/js/components/Switcher.js 334 B
packages/playground/dist/front/js/components/ThemeSwitcher.js 456 B
packages/playground/dist/front/js/create-playground.js 196 B
packages/playground/dist/front/js/loaders/html.js 124 B
packages/playground/dist/front/js/loaders/script.js 124 B
packages/playground/dist/front/js/loaders/style.js 124 B
packages/playground/dist/front/js/store/config.js 468 B
packages/playground/dist/front/js/store/content.js 400 B
packages/playground/dist/front/js/store/header.js 573 B
packages/playground/dist/front/js/store/index.js 109 B
packages/playground/dist/front/js/store/layout.js 606 B
packages/playground/dist/front/js/store/theme.js 516 B
packages/playground/dist/front/js/utils/js/index.js 436 B
packages/playground/dist/front/js/utils/monaco.js 844 B
packages/playground/dist/front/js/utils/patch-iframe-url.js 362 B
packages/playground/dist/front/js/utils/resolve-import-map-urls.js 246 B
packages/playground/dist/front/js/utils/storage/AbstractStorageProvider.js 138 B
packages/playground/dist/front/js/utils/storage/FallbackStorageProvider.js 266 B
packages/playground/dist/front/js/utils/storage/index.js 479 B
packages/playground/dist/front/js/utils/storage/LocalStorageProvider.js 254 B
packages/playground/dist/front/js/utils/storage/MemoryStorageProvider.js 206 B
packages/playground/dist/front/js/utils/storage/MultiStorageProvider.js 307 B
packages/playground/dist/front/js/utils/storage/StorageProviderInterface.js 73 B
packages/playground/dist/front/js/utils/storage/SyncedStorageProvider.js 292 B
packages/playground/dist/front/js/utils/storage/URLStorageProvider.js 365 B
packages/playground/dist/front/js/utils/storage/WatchableStore.js 307 B
packages/playground/dist/front/js/utils/storage/ZipStorageProvider.js 271 B
packages/playground/dist/front/js/utils/twig/index.js 435 B
packages/playground/dist/index.js 154 B
packages/playground/dist/lib/plugins/PlaygroundLoadersPlugin.js 424 B
packages/playground/dist/lib/presets/html-webpack-script-type-module.js 288 B
packages/playground/dist/lib/presets/playground.js 1.07 kB
packages/playground/dist/lib/presets/production-build.js 261 B
packages/playground/dist/lib/tailwind-config.js 509 B
packages/playground/dist/lib/utils/resolve-dependencies.js 3.04 kB
packages/playground/dist/lib/utils/resolve-public-path.js 283 B
packages/playground/dist/lib/utils/zip.js 310 B
packages/playground/dist/preset.js 190 B
packages/playground/dist/tailwind.js 113 B

compressed-size-action

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying studiometa-playground with  Cloudflare Pages  Cloudflare Pages

Latest commit: dfef01c
Status: ✅  Deploy successful!
Preview URL: https://a49db5fd.studiometa-playground.pages.dev
Branch Preview URL: https://fix-dts-chunk-import-extensi.studiometa-playground.pages.dev

View logs

@titouanmathis
titouanmathis merged commit 0e3633d into main Aug 6, 2026
8 checks passed
@codecov

codecov Bot commented Aug 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 34.12%. Comparing base (c14b877) to head (dfef01c).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #76      +/-   ##
==========================================
+ Coverage   33.95%   34.12%   +0.17%     
==========================================
  Files          55       55              
  Lines        1128     1131       +3     
  Branches      230      231       +1     
==========================================
+ Hits          383      386       +3     
  Misses        717      717              
  Partials       28       28              
Flag Coverage Δ
playground 34.12% <100.00%> (+0.17%) ⬆️
playground-preview 34.12% <100.00%> (+0.17%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@titouanmathis
titouanmathis deleted the fix/dts-chunk-import-extension branch August 6, 2026 08:24
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