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
https://github.com/chenjiahan/nodejs-repro-require-import-typescript
// 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.cjs
Ref
Version
Platform
Observed on macOS (x64), but likely reproducible on other platforms.
Description
When loading
typescript, usingimportis ~100ms slower thanrequire.This seems to come from the
cjs-module-lexerstep Node.js runs for CommonJS packages. Sincetypescriptitself is CommonJS,requireavoids the overhead and is noticeably faster.Reproduction
Example results (macOS, Node.js v24.8.0):
Ref