Skip to content

fix: Support Typescript module resolution node16 (#12625)#12982

Open
demurgos wants to merge 1 commit into
react:mainfrom
demurgos:fix/12625-ts-node16
Open

fix: Support Typescript module resolution node16 (#12625)#12982
demurgos wants to merge 1 commit into
react:mainfrom
demurgos:fix/12625-ts-node16

Conversation

@demurgos
Copy link
Copy Markdown

@demurgos demurgos commented Jan 21, 2023

The node16 module resolution for TypeScript adds native support for Node's ESM. In codebases with ESM libraries shared between Node and the frontend, this is the recommended module resolution for native ESM.

Unfortunately, setting the node16 module resolution currently breaks create-react-app. The reason is that imports need an explicit extension, and TypeScript requires to use the output module for resolution; even for bundlers. So foo.ts must be imported as foo.js.

To support this use case, Webpack 5.74.0 introduced the extensionAlias option. This commit updates the Webpack config used by react-scripts to use this new option and fix support for node16 module resolution in TypeScript.

Closes #12625

@facebook-github-bot
Copy link
Copy Markdown

Hi @demurgos!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@demurgos demurgos force-pushed the fix/12625-ts-node16 branch 2 times, most recently from c4f6c17 to 4594ac5 Compare January 21, 2023 19:33
The `node16` module resolution for TypeScript adds native support for Node's ESM. In codebases with ESM libraries shared between Node and the frontend, this is the recommended module resolution for native ESM.

Unfortunately, setting the `node16` module resolution currently breaks `create-react-app`. The reason is that imports need an explicit extension, and TypeScript requires to use the _output_ module for resolution; even for bundlers. So `foo.ts` must be imported as `foo.js`.

To support this use case, [Webpack 5.74.0](https://github.com/webpack/webpack/releases/tag/v5.74.0) introduced the `extensionAlias` option. This commit updates the Webpack config used by `react-scripts` to use this new option and fix support for `node16` module resolution in TypeScript.

Closes react#12625
@facebook-github-bot
Copy link
Copy Markdown

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@SRIKARREDDY-dotorg
Copy link
Copy Markdown

Is this issue still active? What is it keeping open?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support TypeScript module resolution node16

3 participants