Skip to content

Commit 12ce6cb

Browse files
authored
document extension workaround for other bundlers (#195)
1 parent e53e085 commit 12ce6cb

File tree

10 files changed

+1551
-1020
lines changed

10 files changed

+1551
-1020
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
- Fix JSON deserialization. #181 introduced a regression that caused TwirpScript servers' JSON serialization to fail.
1010
- Distribute strict ESM. A CommonJS is runtime is included for legacy node clients. Code generation uses ESM and requires Node.js v14 or later.
11+
If you're using a compiler other than TypeScript such as `webpack`, please see [these instructions](https://github.com/tatethurston/TwirpScript#webpack-setup)
1112
- Use [ProtoScript](https://github.com/tatethurston/ProtoScript) code generation. This will result in some generated imports coming from `protoscript` instead of `twirpscript`, but this is a non breaking change. These imports were previously delegated to ProtoScript via reexports inside TwirpScript, and that indirection has now been removed.
1213

1314
## v0.0.60

README.md

+29
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ TwirpScript implements the latest [Twirp Wire Protocol (v7)](https://twitchtv.gi
5656
- [Working with other tools](#working-with-other-tools)
5757
- [Caveats, Warnings and Issues ⚠️](#caveats-warnings-and-issues-%EF%B8%8F)
5858
- [FAQ](#faq)
59+
- [Webpack Setup](#webpack-setup)
5960
- [Contributing 👫](#contributing-)
6061
- [Licensing 📃](#licensing-)
6162

@@ -99,6 +100,7 @@ To learn more about the motivation behind Twirp (and a comparison to REST APIs a
99100

100101
- Node.js v16 or greater
101102
- TypeScript v4.7 or greater when using TypeScript
103+
- [webpack setup](#webpack-setup) when using a compiler other than TypeScript (like webpack)
102104

103105
## Getting Started
104106

@@ -848,6 +850,33 @@ gRPC is great, but has a large runtime (and corresponding complexity) that is un
848850
849851
To learn more about the motivation behind Twirp (and a comparison to REST APIs and gRPC), check out the [announcement blog](https://blog.twitch.tv/en/2018/01/16/twirp-a-sweet-new-rpc-framework-for-go-5f2febbf35f/).
850852
853+
## Webpack Setup
854+
855+
If you're using a compiler other than TypeScript, such as webpack, this [outstanding issue in TypeScript](https://github.com/microsoft/typescript/issues/37582) adds an additional hurdle.
856+
857+
The short summary of the issue:
858+
859+
- Extensions are required for ESM imports.
860+
- Extension-less imports have sidestepped this TypeScript issue, but extensions are required for ESM adoption.
861+
- The TypeScript compiler requires `.js` extensions for imports.
862+
- Compilers other than TypeScript expect `.ts` extensions for imports.
863+
864+
The TypeScript team is investigating [improving this issue](https://github.com/microsoft/TypeScript/issues/37582) in their [4.9 plan](https://github.com/microsoft/TypeScript/issues/50457)
865+
866+
Webpack users can use [extensionAlias](https://webpack.js.org/configuration/resolve/#resolveextensionalias) to solve this problem:
867+
868+
```diff
869+
module.exports = {
870+
+ resolve: {
871+
+ extensionAlias: {
872+
+ ".js": [".ts", ".js"],
873+
+ },
874+
+ },
875+
};
876+
```
877+
878+
For more context, see [TypeScript#37582](https://github.com/microsoft/typescript/issues/37582) and [Webpack#13252](https://github.com/webpack/webpack/issues/13252).
879+
851880
## Contributing 👫
852881
853882
PR's and issues welcomed! For more guidance check out [CONTRIBUTING.md](https://github.com/tatethurston/twirpscript/blob/main/CONTRIBUTING.md)

0 commit comments

Comments
 (0)