Screening Entry Level

Compare CommonJS and ES modules. How do modern bundlers like Vite, esbuild, and webpack differ in their approach?

Quick Tip

Highlight the key difference: "ES modules are statically analysable so bundlers can tree-shake unused exports. CommonJS require is dynamic so bundlers must include everything. This is why ESM is the future."

What good answers include

CommonJS: synchronous require(), dynamic, used in Node.js. ES modules: static import/export, enables tree-shaking, async loading, now supported in Node.js and browsers. Webpack: established, plugin-rich, bundles everything into chunks. Esbuild: extremely fast (Go-based), limited plugin API. Vite: uses native ES modules in dev (no bundling), esbuild for transpilation, Rollup for production builds. Strong candidates discuss tree-shaking requirements (ES modules only), code splitting strategies, and why Vite dev server is fast.

What interviewers are looking for

Tests ecosystem knowledge. Candidates who only know webpack may not be up to date. Those who understand why Vite uses native ESM in dev and Rollup in production demonstrate modern tooling awareness.

← All JavaScript questions