Title: `import "typescript"` slower than `require("typescript")` due to `cjs-module-lexer` overhead · Issue #59913 · nodejs/node · GitHub
Open Graph Title: `import "typescript"` slower than `require("typescript")` due to `cjs-module-lexer` overhead · Issue #59913 · nodejs/node
X Title: `import "typescript"` slower than `require("typescript")` due to `cjs-module-lexer` overhead · Issue #59913 · nodejs/node
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-modul...
Open Graph 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 requir...
X 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 requir...
Opengraph URL: https://github.com/nodejs/node/issues/59913
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`import \"typescript\"` slower than `require(\"typescript\")` due to `cjs-module-lexer` overhead","articleBody":"### Version\n\n- Node.js v24.8.0\n- Node.js v22.18.0\n\n### Platform\n\nObserved on macOS (x64), but likely reproducible on other platforms.\n\n### Description\n\nWhen loading `typescript`, using `import` is ~100ms slower than `require`.\n\nThis 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.\n\n\u003cimg width=\"2368\" height=\"1322\" alt=\"Image\" src=\"https://github.com/user-attachments/assets/d0ec96bb-4b96-4222-843e-e45bd9138f96\" /\u003e\n\n### Reproduction\n\n\u003e https://github.com/chenjiahan/nodejs-repro-require-import-typescript\n\n```js\n// import.mjs\nimport typescript from \"typescript\";\n\nconsole.log(typescript);\n\n// require.cjs\nconst typescript = require(\"typescript\");\n\nconsole.log(typescript);\n```\n\n**Example results (macOS, Node.js v24.8.0):**\n\n```bash\n# ~200ms\ntime node ./import.mjs\n\n# ~100ms\ntime node ./require.cjs\n```\n\n### Ref\n\n* https://x.com/matteocollina/status/1968303799271047230 @mcollina \n","author":{"url":"https://github.com/chenjiahan","@type":"Person","name":"chenjiahan"},"datePublished":"2025-09-17T13:45:47.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":10},"url":"https://github.com/59913/node/issues/59913"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:9abeabbe-9fae-d7fb-eaa3-2a80311174e2 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A1AE:1DA4B8:18163CA:2170FC5:6A4C1006 |
| html-safe-nonce | 15c028327dd329bdb65938874bd19fc1b0fc8fb3f5ca7fbbe8e64ae6102f5a32 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMUFFOjFEQTRCODoxODE2M0NBOjIxNzBGQzU6NkE0QzEwMDYiLCJ2aXNpdG9yX2lkIjoiODc5MDIzMzMyNzA5NDk5MjkwMiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 28005a75a12ca0929197c353bf059a3df91d3dedf8dc8423e84240a704929693 |
| hovercard-subject-tag | issue:3426390504 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/nodejs/node/59913/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e29206cbcca9743d309097caf51a332ba2d07ee7b096f38989cc9babc66285c6/nodejs/node/issues/59913 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e29206cbcca9743d309097caf51a332ba2d07ee7b096f38989cc9babc66285c6/nodejs/node/issues/59913 |
| og:image:alt | 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 requir... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | chenjiahan |
| hostname | github.com |
| expected-hostname | github.com |
| None | 0ccfc9e5281bfe12e38a4d632dc422843e4d5b6757917f7efda2f6567d72fea9 |
| turbo-cache-control | no-preview |
| go-import | github.com/nodejs/node git https://github.com/nodejs/node.git |
| octolytics-dimension-user_id | 9950313 |
| octolytics-dimension-user_login | nodejs |
| octolytics-dimension-repository_id | 27193779 |
| octolytics-dimension-repository_nwo | nodejs/node |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 27193779 |
| octolytics-dimension-repository_network_root_nwo | nodejs/node |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 18812876666a23a0912556e224383baa4c84cf8e |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width