Skip to content

Instantly share code, notes, and snippets.

@andrewbranch
Last active January 10, 2024 18:44
Show Gist options
  • Star 82 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save andrewbranch/79f872a8b9f0507c9c5f2641cfb3efa6 to your computer and use it in GitHub Desktop.
Save andrewbranch/79f872a8b9f0507c9c5f2641cfb3efa6 to your computer and use it in GitHub Desktop.
Module documentation
@MrHBS
Copy link

MrHBS commented Jul 22, 2023

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.

@andrewbranch
Copy link
Author

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.

@MrHBS
Copy link

MrHBS commented Jul 24, 2023

Thank you very much Andrew! This makes sense now.

@GabenGar
Copy link

GabenGar commented Sep 3, 2023

See the reference section on nodenext for more details.

The link in this sentence is broken.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment