The WIP content that was here is now live at http://typescriptlang.org/docs/handbook/modules/introduction.html
-
-
Save andrewbranch/79f872a8b9f0507c9c5f2641cfb3efa6 to your computer and use it in GitHub Desktop.
If all input sources in any TypeScript program are ESM, then esModuleInterop
should be irrelevant. However, that’s not necessarily the situation you’re describing. The module system you’re targeting with your build is a bundler that can handle both ESM and CJS (inside dependencies), not a browser that can only handle ESM. If you have any node_modules at all, there’s a very good chance that some of them are CJS, and Vite will convert them to ESM before bundling. What Vite outputs is irrelevant to your TS module-related settings. So yes, you should still set esModuleInterop
in these cases. If you were writing ESM that you were going to ship straight to the browser unprocessed, then esModuleInterop
would be irrelevant.
Thank you very much Andrew! This makes sense now.
See the reference section on nodenext for more details.
The link in this sentence is broken.
So I suppose if you are making a website and target browsers (ESM only), you can just ignore esModuleInterop? Or do I still need to set it to true “just in case”? Reason I ask is because esbuild instructs on setting this to true, which is used by Vite, which is used by Nuxtjs. Basically I wonder if this setting matters for frameworks.