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

fix(js): set compilerOptions correctly when loading .ts that targets ESM #27862

Merged
merged 1 commit into from
Sep 12, 2024

Conversation

jaysoo
Copy link
Member

@jaysoo jaysoo commented Sep 10, 2024

When we load .ts files and the closest package.json specifies "type": "module", then the file may error upon loading. This happens because we're not setting compilerOptions correctly when registering ts-node/esm-- in fact there is no way to pass options through this hook.

This PR sets defaults on TS_NODE_COMPILER_OPTIONS such that the module and moduleResolution are correct values for ESM. It also works for CJS since both module and moduleResolution check the closest package.json to determine the format.

Current Behavior

Expected Behavior

Related Issue(s)

Fixes #23228

@jaysoo jaysoo requested a review from a team as a code owner September 10, 2024 20:18
@jaysoo jaysoo requested a review from FrozenPandaz September 10, 2024 20:18
Copy link

vercel bot commented Sep 10, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Updated (UTC)
nx-dev ⬜️ Ignored (Inspect) Visit Preview Sep 11, 2024 2:05pm

@jaysoo jaysoo merged commit 7232b39 into master Sep 12, 2024
6 checks passed
@jaysoo jaysoo deleted the issue/NXC-885 branch September 12, 2024 22:47
FrozenPandaz pushed a commit that referenced this pull request Sep 18, 2024
…ESM (#27862)

When we load `.ts` files and the closest `package.json` specifies
`"type": "module"`, then the file may error upon loading. This happens
because we're not setting `compilerOptions` correctly when registering
`ts-node/esm`-- in fact there is no way to pass options through this
hook.

This PR sets defaults on `TS_NODE_COMPILER_OPTIONS` such that the
`module` and `moduleResolution` are correct values for ESM. It also
works for CJS since both `module` and `moduleResolution` check the
closest `package.json` to determine the format.

## Current Behavior
<!-- This is the behavior we have today -->

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #23228

(cherry picked from commit 7232b39)
Copy link

This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Most nx cli commands fail when @nx/storybook attempts parse storybook's main.ts
2 participants