Skip to content

fix(core): handle builtin imports in linked esm loader#1070

Merged
9aoy merged 2 commits intomainfrom
fix/core-esm-loader-linked-imports
Mar 19, 2026
Merged

fix(core): handle builtin imports in linked esm loader#1070
9aoy merged 2 commits intomainfrom
fix/core-esm-loader-linked-imports

Conversation

@Timeless0911
Copy link
Copy Markdown
Contributor

@Timeless0911 Timeless0911 commented Mar 18, 2026

Summary

Background

The worker ESM loader resolves non-absolute specifiers during module linking. Linked modules that statically import Node builtins can fall into that path and fail when builtin specifiers are treated like regular file imports.

Implementation

  • Detect builtin specifiers, including both node: imports and bare builtin module names, before calling import.meta.resolve.
  • Pass builtin specifiers through unchanged so Node can load them natively in linked modules.
  • Add a regression test covering a linked chunk that statically imports node:fs and node:path.

User Impact

Linked ESM chunks that import Node builtins now load correctly in @rstest/core workers.

Related Links

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 18, 2026

📝 Rstest Ecosystem CI: Open

suite result
examples ✅ success
rsbuild ✅ success
rspress ✅ success
rsdoctor ✅ success
modernjs ✅ success
rslib ✅ success

@Timeless0911 Timeless0911 marked this pull request as draft March 19, 2026 03:58
@Timeless0911 Timeless0911 changed the title fix(core): handle linked esm imports in loader fix(core): handle builtin imports in linked esm loader Mar 19, 2026
@Timeless0911 Timeless0911 marked this pull request as ready for review March 19, 2026 07:05
@9aoy 9aoy merged commit 3599eae into main Mar 19, 2026
18 checks passed
@9aoy 9aoy deleted the fix/core-esm-loader-linked-imports branch March 19, 2026 07:09
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 078c91971a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +76 to +77
: isBuiltinSpecifier(specifier)
? specifier
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep bare builtins canonicalized to node:

Returning specifier here means bare builtins like fs and path no longer go through import.meta.resolve, so modulePath stays 'fs' instead of 'node:fs'. With the default interopDefault: true, that makes the later !modulePath.startsWith('node:') guard miss these modules and wraps each await import('fs') in a fresh interop Proxy instead of returning Node’s cached module namespace object. Any ESM test code that compares repeated builtin imports or uses them as identity-stable keys will now behave differently from native Node semantics.

Useful? React with 👍 / 👎.

@9aoy 9aoy mentioned this pull request Mar 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants