Skip to content

Commit bf502dd

Browse files
authored
docs(readme): add opt in section
1 parent 6399038 commit bf502dd

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

README.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,28 @@
3535
<small><i><a href='#'>This is a work in progress</a></i></small>
3636

3737

38-
## Overview
38+
## Motivation
3939

40+
Establishing the best way to support cjs and esm and how to structure project to enable that (see results.txt for more info)
4041

41-
Testing best way to support cjs and esm and how to structure project to enable that (see results.txt for more info)
42+
### Opt in compiler options
43+
44+
**disable** the following compiler options:
45+
46+
`esModuleInterop`: `false`
47+
`allowSyntheticDefaultImports`: `false`
48+
49+
50+
The two flags `esModuleInterop` and `allowSyntheticDefaultImports` enable interoperation between ES Modules and CommonJS, AMD, and UMD modules for emit from TypeScript and type resolution by TypeScript respectively.
51+
52+
Unfortunately these options are viral: **enabling them in a package requires all downstream consumers to enable them as well** . The TLDR is due to the way CommonJS and ES Modules interoperate with bundlers (Webpack, Parcel, etc.).
53+
54+
### Solution
55+
56+
set both `allowSyntheticDefaultImports` and `esModuleInterop` to `false`.
57+
58+
Consumers can now opt into these semantics, it also does not require them to do so.
59+
Consumers **can always safely use alternative import syntaxes (including falling back to require() and import()),** or can enable these flags and opt into this behavior themselves.
4260

4361
## TLDR
4462

0 commit comments

Comments
 (0)