fix: Support Typescript module resolution node16 (#12625)#12982
fix: Support Typescript module resolution node16 (#12625)#12982demurgos wants to merge 1 commit into
node16 (#12625)#12982Conversation
|
Hi @demurgos! Thank you for your pull request and welcome to our community. Action RequiredIn 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. ProcessIn 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 If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
c4f6c17 to
4594ac5
Compare
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
4594ac5 to
8c543d8
Compare
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
|
Is this issue still active? What is it keeping open? |
The
node16module 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
node16module resolution currently breakscreate-react-app. The reason is that imports need an explicit extension, and TypeScript requires to use the output module for resolution; even for bundlers. Sofoo.tsmust be imported asfoo.js.To support this use case, Webpack 5.74.0 introduced the
extensionAliasoption. This commit updates the Webpack config used byreact-scriptsto use this new option and fix support fornode16module resolution in TypeScript.Closes #12625