Open DanielRosenwasser opened 1 month ago
- Lots of bundlers say this just echoes the string pkg to the console.
- esbuild and Webpack do the "Node-specific" behavior
Vite uses esbuild so I'm wondering which bundlers do the non-Node behavior? I checked out the linked issues but could not immediately see a list.
@andrewbranch knows best - Parcel, Bun, and Rollup at least come to mind.
Parcel, Bun, and Rollup are the ones I tested latest versions of in preparation for this design meeting. Versions are a little older, but Vite is included in https://andrewbranch.github.io/interop-test/#default-export-esmodulejs and you can see it’s aligned with Parcel/Bun/Rollup, not esbuild/Webpack. Vite uses Rollup in production and esbuild in development. The report linked above is showing results with Vite instrumented in production mode. I’m not sure whether it’s possible to observe the esbuild interop behavior in Vite development mode.
Options for
import cjs from "cjs"
andrequire(esm)
https://github.com/microsoft/TypeScript/issues/54102
moduleFormatInterop
- https://github.com/microsoft/TypeScript/pull/58480defaultIsModuleExports
andallowRequireESM
- https://github.com/microsoft/TypeScript/pull/58526What is the motivating example?
pkg
to the console.vendor/pkg/index.js
is brought in as adefault
import, and itself is an object with adefault
property. So it logs either[Object object]
or{ __esModule: true, default: "pkg" }
.defaultIsModuleExports
to control the import cjs from "cjs"` behavior."type": "module"
often isn't specified (or people don't use.mts
).Checking of string literal union object keys and template types
https://github.com/microsoft/TypeScript/issues/58673
{ [... as "x" | "y"]: string }
would be equivalent to{ x: string } | { y: string }
.{ [... as `foo${string}`]: string }
- should this be equivalent to{ [props: `foo${string}`]: string }
?noUncheckedIndexedAccess
.A few different treatments.
{ x: number, y: number }
because literal types desugar into individual properties.