-
-
Notifications
You must be signed in to change notification settings - Fork 34.4k
Open
Description
Version
- Node.js v24.8.0
- Node.js v22.18.0
Platform
Observed on macOS (x64), but likely reproducible on other platforms.
Description
When loading typescript, using import is ~100ms slower than require.
This seems to come from the cjs-module-lexer step Node.js runs for CommonJS packages. Since typescript itself is CommonJS, require avoids the overhead and is noticeably faster.
Reproduction
// import.mjs
import typescript from "typescript";
console.log(typescript);
// require.cjs
const typescript = require("typescript");
console.log(typescript);Example results (macOS, Node.js v24.8.0):
# ~200ms
time node ./import.mjs
# ~100ms
time node ./require.cjsRef
qweered, gameroman, jlucaso1, andriyor, H4ad and 6 more
Metadata
Metadata
Assignees
Labels
No labels