fix: guard parent access in addTsEsmHook for ESM-to-CJS sub-dependency resolution#1087
Open
setthase wants to merge 1 commit intohapijs:masterfrom
Open
fix: guard parent access in addTsEsmHook for ESM-to-CJS sub-dependency resolution#1087setthase wants to merge 1 commit intohapijs:masterfrom
addTsEsmHook for ESM-to-CJS sub-dependency resolution#1087setthase wants to merge 1 commit intohapijs:masterfrom
Conversation
4ee1b6d to
d7a95fa
Compare
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.
What: Adds a null guard for
parentininternals.addTsEsmHook()(lib/cli.js).Why: When running TypeScript tests (
--typescript) in an ESM project that imports from an ESM package with CJS sub-dependencies, the crash path is:require.extensions['.ts']→Module._compile→loadESMFromCJS→ ESM translators → CJS sub-dependency resolution →Module._resolveFilenamewithparent === undefined. The current code accessesparent.filenameunconditionally, causingTypeError: Cannot read properties of undefined (reading 'filename').Fix: Guard the
parentaccess so that whenparentisundefined(ESM-to-CJS transition context), the hook falls through to the original_resolveFilename, which handles the resolution natively.Test: Added
test/cli_typescript_esm_dep/fixture — a TypeScript ESM test that imports from an ESM package which has a CJS sub-dependency (two-layer structure required to trigger the crash). Without the fix, this crashes. With the fix, it passes.Ref: fixes #1086