Repository navigation
fix: Respect package.json exports when adding extensions to package imports - #212
Merged
Merged
Conversation
…mports Package imports got a file extension whenever a matching file existed on disk, without looking at the package's "exports" field. For a package that exports "./sub" and also ships sub.js, "pkg/sub" became "pkg/sub.js", which Node.js rejects with ERR_PACKAGE_PATH_NOT_EXPORTED. Package imports are now checked with TypeScript's module resolver in NodeNext ESM mode. An import that resolves as written stays untouched, and an extension is only added when the import doesn't resolve without it but does with it. This also covers package roots like "@playwright/test" (#81), so the isNodeModuleRoot special case is gone.
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 #128
Package imports got a file extension whenever a matching file existed on disk. The package's
exportsfield was never read. For a package that exports./suband also shipssub.js,modern/subbecamemodern/sub.js, and Node.js rejects that withERR_PACKAGE_PATH_NOT_EXPORTED. The firebase example in the issue only worked because that package happens not to have a file atv1/https.js.Package imports are now checked with TypeScript's module resolver in NodeNext ESM mode, as suggested in #123:
firebase-functions/v1/https,@playwright/test)..jsor/index.jsis added if that makes it resolve (lodash/omitbecomeslodash/omit.js).An earlier attempt used the project's own compiler options. Those are CommonJS before the migration, so
lodash/omitresolved without an extension. Resolving in ESM mode gives the answer Node.js will give after the migration.This also covers package roots from #81, so
isNodeModuleRootand its special case are removed.The new fixture ships a few fake packages in
node_modules, so.gitignoregets an exception for fixturenode_modulesfolders.