Skip to content

fix(core): treat a # in an ES module specifier as a fragment - #859

Merged
Brooooooklyn merged 2 commits into
mainfrom
fix/issue-856
Oct 17, 2026
Merged

Brooooooklyn merged 2 commits into
mainfrom
fix/issue-856

Conversation

@Brooooooklyn

@Brooooooklyn Brooooooklyn commented Oct 17, 2026 •

Copy link
Copy Markdown
Member

Closes #856

Problem

In an ES module import, # starts a URL fragment: Node.js resolves import './a#b.ts' as ./a with the fragment #b.ts. Since #847, oxc-node loaded a file named a#b.ts instead, whenever one existed. oxc_resolver follows enhanced-resolve: for a specifier with a # and no ?, load_parse first tries the whole specifier as a path. #847 re-attached the raw ?query#fragment to the resolver's specifier, so file: URLs with a fragment were affected the same way.

Fix

A URL reference's query and fragment never reach the resolver now. A URL reference is a file: URL, or a relative or absolute-path specifier in ESM. Its decoded pathname is resolved on its own, and the raw suffix is appended to the resolved URL, as Node.js does. resolver_request no longer takes a suffix.

require() is unaffected: register.mjs hands every require() request (no importAttributes) to Node.js' own CommonJS resolution before createResolve runs, so # and % stay file-name characters there. The request kind isn't inferred from the require condition, which --conditions=require adds to imports too.

Verification

Module URLs match plain Node exactly: ./url.mjs#one gives …/url.mjs#one, ./url.mjs?q#two gives …/url.mjs?q#two, and an encoded ./a%23b.mjs still loads a#b.mjs.

Tests

🤖 Generated with Claude Code

oxc_resolver follows enhanced-resolve: for a specifier with a `#` and no
`?` it first tries the whole specifier as a path. Since #847 encodes the
resolved path, `import './a#b.ts'` therefore loaded a file named `a#b.ts`
where Node.js resolves `./a` with the fragment `#b.ts`; a file URL with a
fragment had the same problem.

Keep a URL reference's `?query` / `#fragment` back from the resolver:
resolve its decoded pathname alone and append the suffix to the resolved
URL, as Node.js does. A `require()` specifier, recognised by its `require`
condition, stays a path with `#`, `?` and `%` as file-name characters, as
Node.js' CommonJS resolution reads it.

Closes #856

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-17T04:34:37.318519Z aef5c3a New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

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

Copy link
Copy Markdown

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: 1266bb90b0

ℹ️ 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 thread src/lib.rs Resolved
`--conditions=require` adds `require` to every request's conditions, so an
import under it took the CommonJS branch and loaded `a#b.ts` for
`./a#b.ts` again. That branch was never needed: register.mjs hands every
require() request, recognised by its missing importAttributes, to Node.js'
own CommonJS resolution before createResolve is reached. Drop it.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@Brooooooklyn
Brooooooklyn merged commit 1c23b37 into main Oct 17, 2026
67 checks passed
@Brooooooklyn
Brooooooklyn deleted the fix/issue-856 branch October 17, 2026 04:49
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.

Since #847, a relative import with # loads the file named with the # instead of treating #… as a fragment

1 participant