Repository navigation
Conversation
… require exports resolveEntry resolved the package with createRequire().resolve, which uses the require conditions, and only read the import entry when that threw ERR_PACKAGE_PATH_NOT_EXPORTED. The entry is then loaded with import(), so a package exporting both entries gave the require one. Read the import target from exports first; keep require resolution for packages whose exports give no import target or that have no exports. Fixes e2e-inc#1758
There was a problem hiding this comment.
All reported issues were addressed across 3 files
Heads up: you’ve reached your flex budget. Increase your flex budget or wait for usage to reset.
View guided diff | Re-trigger cubic
A subpath that only a "./*" style exports key matches got no import target, so resolution fell back to require.resolve and loaded the CommonJS file. Match patterns the way Node.js does: longest part before "*" wins, then the longest key, and the matched text replaces every "*" in the target.
There was a problem hiding this comment.
0 issues found across 2 files (changes from recent commits).
Heads up: you’ve reached your flex budget. Increase your flex budget or wait for usage to reset.
View guided diff | Re-trigger cubic
okwasniewski
left a comment
There was a problem hiding this comment.
[claude-opus-5-5] automated review on behalf of @okwasniewski
Thanks for the quick fix! #1762 also fixes #1758, so both PRs get the same comparison.
I tested it with a fake engine package in 22 export shapes and compared the file each resolver picks with the file a real import() loads (Node 24). Main picks the wrong file in 13 of them. This PR gets every common shape right: import-first and require-first, nested node: {import, require}, require + default, subpaths, ./* patterns, sugar strings, main-only packages and pnpm symlinks. Both new tests fail on main's source, and so does dropping the wildcard commit.
The problem is that importEntry/importTarget (default-engine.ts:188-219) grow a hand-written copy of Node's exports resolver, pattern ranking included, and it still differs from import() in real cases:
- An array of condition objects loads the
requirefile. module-syncis ignored.{import: null, require}loadsrequireinstead of failing.- An
importarray whose first file is missing falls back torequire. - Targets that don't start with
./or that contain../are accepted, so{import: '../other/x.js'}loads a file outside the package. Main already had this, but it is now the main path. :165throws inside thetryonly so its owncatchcan wrap the error.
We'd rather not maintain our own resolver. A single resolve call with conditions: ['node', 'import', 'module-sync'] (e.g. exsolve's resolveModuleURL), plus main's createRequire().resolve as a fallback on ERR_PACKAGE_PATH_NOT_EXPORTED for CommonJS-only engines, matched import() in all 22 cases. Whether e2e takes a resolver dependency is a maintainer call, and so is which of the two PRs carries the fix. If the dependency is refused, this PR is the base. In that case please reject targets that don't start with ./ or that leave the package, and handle null and arrays the way Node does.
Follow Node.js's target rules: targets must start with ./ and stay in the package, null excludes, arrays fall back past invalid or null items, module-sync counts as a condition. The entry check moves out of the try so its own catch no longer wraps it.
|
Thanks for the thorough comparison. Agreed that a real resolver beats a hand-written one. If you take the dependency, #1762 is the better base and I'm happy to close this one. So this PR is a solid fallback in case the dependency is refused, I did the asks in 471719e:
I checked the new cases against a real |
There was a problem hiding this comment.
All reported issues were addressed across 3 files (changes from recent commits).
Heads up: you’ve reached your flex budget. Increase your flex budget or wait for usage to reset.
View guided diff | Re-trigger cubic
There was a problem hiding this comment.
0 issues found across 2 files (changes from recent commits).
Heads up: you’ve reached your flex budget. Increase your flex budget or wait for usage to reset.
View guided diff | Re-trigger cubic
|
[claude-opus-5-5] automated review on behalf of @okwasniewski Thanks for doing all the asks and for the offer. A maintainer is deciding on the
No need to push until the dependency question is settled. |
|
Sounds good. I've done the four items locally ( |
What and why
resolveEntryinpackages/e2e/src/mcp/default-engine.tsfound the entry withcreateRequire().resolve(), so it used therequireconditions. It only read theimportentry when that threwERR_PACKAGE_PATH_NOT_EXPORTED. The entry is then loaded withimport(), so a package that exports both picked therequirefile.importtarget fromexportsfirst (the existingimportEntryhelper:import,node, ordefault, in the order written).requireresolution stays for packages whoseexportsgive no import target, or that have noexports.importtarget that is missing on disk is reported as "installed ... but its entry cannot be resolved", like the other unloadable entries, instead of falling back to therequirefile.e2e. No docs change: the docs do not describe how the entry is picked.Issue
Fixes #1758
Verified
Ran it locally: yes
mcp-default-engine.test.ts: a package with{ import: './index.js', require: './index.cjs' }on.and on a subpath (writtenrequirefirst), each file returning an engine with a different name.from-require(test fails)from-importfordualanddual/webvitest run tests/unit: 3654 pass, 1 skipped.pnpm checkgreen.Checklist
pnpm changeset) for any change to a published package, or the change is testbed, docs, or CI only.!, the changeset body names what breaks and what replaces it, and the deprecation warning landed a window earlier (stability policy in CONTRIBUTING.md).docs/**/*.mdxpage for the behavior, andskills/e2e/if the skill describes it..d.tsreviewed,tests/types/sdk-types.tsupdated; wire change edits the schema and both fixtures.e2e/engine): changesets fore2e,@e2e-dev/web, and@e2e-dev/mobile.