Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load TypeScript in ESM mode if package.json type is module #1849

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

henrist
Copy link

@henrist henrist commented Jan 14, 2025

Description

Closes #1848

Motivation and Context

See #1848

How Has This Been Tested?

Tested on a service locally that failed previously. See #1848 for environment details.

Screenshots (if appropriate):

N/A

@henrist henrist changed the title Load in ESM mode if package.json type is module Load TypeScript in ESM mode if package.json type is module Jan 14, 2025
@DorianMazur
Copy link
Collaborator

DorianMazur commented Jan 17, 2025

@henrist Thank you for the PR! Can you create new test for this?

@henrist
Copy link
Author

henrist commented Jan 20, 2025

@DorianMazur Test added (and added a missing inclusion of the commonjs variant).

Making the test fail before my fixes requires a bit of code. For context this is the error:

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in /Users/henrste/repo/node_modules/dependency/package.json
    at exportsNotFound (node:internal/modules/esm/resolve:314:10)
    at packageExportsResolve (node:internal/modules/esm/resolve:605:13)
    at resolveExports (node:internal/modules/cjs/loader:638:36)
    at Function._findPath (node:internal/modules/cjs/loader:743:31)
    at node:internal/modules/cjs/loader:1230:27
    at nextResolveSimple (/Users/henrste/repo/node_modules/.pnpm/tsx@4.19.2/node_modules/tsx/dist/register-DCnOAxY2.cjs:3:942)
    at /Users/henrste/repo/node_modules/.pnpm/tsx@4.19.2/node_modules/tsx/dist/register-DCnOAxY2.cjs:2:2550
    at /Users/henrste/repo/node_modules/.pnpm/tsx@4.19.2/node_modules/tsx/dist/register-DCnOAxY2.cjs:2:1624
    at resolveTsPaths (/Users/henrste/repo/node_modules/.pnpm/tsx@4.19.2/node_modules/tsx/dist/register-DCnOAxY2.cjs:3:760)
    at Function._resolveFilename (/Users/henrste/repo/node_modules/.pnpm/tsx@4.19.2/node_modules/tsx/dist/register-DCnOAxY2.cjs:3:1038)

When a package declares conditional exports using the exports field, the CommonJS loader does not load an import export.

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.

ESM mode not supported for TypeScript
2 participants