Repository navigation
Conversation
A require() call in an ES module (through module.createRequire, or the global require with mixedModules) was resolved with the "import" condition, because every specifier in `deps` was resolved as an import when the containing file was ESM. For a dual package whose exports subpath has separate import and require targets, the ESM build was traced while Node loads the CommonJS one. Static import and export-from declarations now go into `imports`, next to dynamic import(), and `deps` only holds require-like references, which are always resolved with the "require" condition. Fixes vercel#621
RClaudiuM
requested review from
a team,
icyJoseph,
ijjk and
styfle
as code owners
November 7, 2026 21:28
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.
Fixes #621
What
A
require()call inside an ES module (throughmodule.createRequire, or the globalrequirewithmixedModules) was resolved with theimportcondition.emitDependencyresolved every specifier indepswithcjsResolve = !isESM, and in an ES moduledepsheld both the staticimport/export ... fromdeclarations and therequire()calls. For a dual package whoseexportssubpath has separateimportandrequiretargets, nft traced the ESM build while Node loads the CommonJS one, so the deployed function fails withMODULE_NOT_FOUND.Fix
analyzenow adds staticimportandexport ... fromsources toimports, next to dynamicimport()(andmodule.register), which are already resolved with theimportcondition.depsnow only holds require-like references (require(),createRequire,require.resolve, special cases, wildcard requires), soemitDependencyalways resolves it with therequirecondition.Relative and absolute paths resolve the same way under both conditions, so this only changes bare and
#specifiers reached throughrequire()in an ES module.Tests
New unit fixture
esm-require-exports-conditions: an ES module importsdual/importedand requiresdual/requiredthroughcreateRequire. Each subpath has separateimportandrequiretargets.esm/imported.jsandesm/required.js(the test fails).esm/imported.jsandcjs/required.js.The repro from the issue (
createRequire+require("dual/sub")), withmixedModulesbothtrueandfalse:pnpm prettier-check,pnpm buildandpnpm testpass locally. The exceptions are the bcrypt, ffmpeg-static and leveldown integration tests: they fail the same way onmainhere because I installed without running native build scripts.