Files
scriptc/docs/content/limitations/language-features/commonjs-require.mdx
T
Chris Tate 9f2e9b00c9 Write the limitations partials one sentence per line
Each limitations partial held its whole text on one line (map-and-set.mdx
was a single 1,080-character line), so any two edits to the same partial
conflicted. The partials now put one sentence per line, with a bullet's
continuation lines indented two spaces. Markdown joins the lines, so the
rendered pages are unchanged.

scripts/limitations-partials.mjs reads a labeled bullet's indented
continuation lines as part of the bullet when it splits and joins the page,
and AGENTS.md states the convention.
2026-10-19 00:11:31 -05:00

10 lines
1.0 KiB
Plaintext

- **CommonJS `require`:** Literal `require()` calls of compiled modules, supported builtins, and JSON documents compile.
Reading a top-level `const` or `let` require binding before its `require` runs throws the same `ReferenceError` as Node.js.
A `var` binding that code above its `require` can reach is unsupported, and so is a read that compiles to no checkable expression, such as exporting the binding before the `require`.
JSON documents are parsed at build time, and every `require()` of a document returns the same object.
Destructuring the exports of a module supports plain and renamed properties, plus nested patterns for builtin sub-modules such as `util.types`.
Any pattern works on a JSON document.
Defaults, rest elements, and nested patterns over other modules are unsupported.
A require cycle compiles when each of its modules assigns all of its exports before its first `require` and uses the other modules of the cycle only inside functions that its top-level code can't call.
Other require cycles are rejected with `SC1016`.