An update added 35KB to your bundle? A barrel file with a default export likely blocked tree-shaking.
20+ years shipping production JavaScript and front-end systems at scale. Notes here come from systems that actually shipped.
export to expose and import to consume — no more global pollutionexport const) force explicit naming at import site, improving refactoringexport default) are for the file's primary responsibility, rename without asimport() returns a Promise — lazy load modules on user interaction"type": "module" in package.json; browsers use
import() is a function that returns a Promise—ideal for code splitting and reducing initial bundle size.require() is dynamic and can be called inside loops.SyntaxError: Cannot use import statement outside a module. App fails to load with no clear stack trace in production because minifiers may swallow the error.type="module" to the <script> tag. If using a bundler, ensure it outputs in a format that doesn't require the attribute (bundled output usually runs as normal scripts).resolve.extensions doesn't include .js.import { helper } from './helpers.js'. In bundlers, configure resolve.extensions appropriately. For Node.js ESM, extensions are required unless using experimental-specifier-resolution=node.ReferenceError: require is not defined because ESM does not have require in the global scope. Some older patterns like const fs = require('fs') stop working.require() with import. If you need dynamic behaviour, use await import() instead. For interop, consider using the createRequire function from module module to create a local require function.Explain 'Tree Shaking' and why ES Modules make it possible while CommonJS makes it difficult.
requires() can be dynamic (called inside if-blocks, loops, or functions), so the bundler cannot safely determine which exports are used without executing the code. Therefore, CommonJS modules are included in their entirety.20+ years shipping production JavaScript and front-end systems at scale. Notes here come from systems that actually shipped.
5 min read · try the examples if you haven't