Performance: CommonJS vs ESM differences
MEDIUM IMPACT
This affects module loading speed and runtime execution efficiency in Node.js applications.
import fs from 'fs'; import path from 'path'; // ESM loads modules asynchronously and supports static analysis
const fs = require('fs'); const path = require('path'); // multiple require calls synchronously load modules
| Pattern | Module Loading | Blocking | Bundle Size | Verdict |
|---|---|---|---|---|
| CommonJS require() | Synchronous | Blocks event loop | Includes all code | [X] Bad |
| ESM import | Asynchronous | Non-blocking | Supports tree shaking | [OK] Good |