aboutsummaryrefslogtreecommitdiff
path: root/docs/runtime
diff options
context:
space:
mode:
authorGravatar Dan Fabulich <dan@fabulich.com> 2023-09-08 11:18:52 -0700
committerGravatar GitHub <noreply@github.com> 2023-09-08 11:18:52 -0700
commit989dd92ea8bf249cf7e32962d587a35d7b0c1277 (patch)
treee69b890941ca7e95fa293c20d5601cb31c8832ea /docs/runtime
parent9e3cabc540149eae31cffff104a3642792a2ae79 (diff)
downloadbun-989dd92ea8bf249cf7e32962d587a35d7b0c1277.tar.gz
bun-989dd92ea8bf249cf7e32962d587a35d7b0c1277.tar.zst
bun-989dd92ea8bf249cf7e32962d587a35d7b0c1277.zip
Move "Importing CJS from CJS" back out of low-level details section (#4600)
This section appears to have been accidentally moved into the low-level details section in 5424ea3403df9cd4672290865f12b6f5b01cf2d0. This fixes the example in the low-level details section, because the "Importing CJS from CJS" section is not the example code that the low-level details section is intended to provide.
Diffstat (limited to 'docs/runtime')
-rw-r--r--docs/runtime/modules.md14
1 files changed, 6 insertions, 8 deletions
diff --git a/docs/runtime/modules.md b/docs/runtime/modules.md
index dd48dfa46..349fd3594 100644
--- a/docs/runtime/modules.md
+++ b/docs/runtime/modules.md
@@ -201,6 +201,12 @@ const myStuff = require("./my-commonjs.cjs");
const { stuff } = require("./my-esm.mjs");
```
+### Importing CommonJS from CommonJS
+
+```ts
+const { stuff } = require("./my-commonjs.cjs");
+```
+
#### Top-level await
If you are using top-level await, you must use `import()` to import ESM modules from CommonJS modules.
@@ -218,14 +224,6 @@ const { stuff } = require("./my-esm.js");
Bun's JavaScript runtime has native support for CommonJS. When Bun's JavaScript transpiler detects usages of `module.exports`, it treats the file as CommonJS. The module loader will then wrap the transpiled module in a function shaped like this:
-### Importing CommonJS from CommonJS
-
-You can `require()` CommonJS modules from CommonJS modules.
-
-```ts
-const { stuff } = require("./my-commonjs.cjs");
-```
-
```js
(function (module, exports, require) {
// transpiled module
n&id=0f853a2fee89aec4a8006412340e82d504bb01da&follow=1'>Update js_printer.zigGravatar Jarred Sumner 1-1/+1 2021-12-16:camera:Gravatar Jarred Sumner 30-129/+226 2021-12-16bump build idGravatar Jarred Sumner 1-1/+1 2021-12-16[macros] Do not automatically load node_modules.bun in macrosGravatar Jarred Sumner 1-11/+11 2021-12-16[macros] Slightly improve error message if macros fail to loadGravatar Jarred Sumner 1-2/+7 2021-12-16[bundler][JS transpiler] Improve reliability of ESM <> CommonJS interopGravatar Jarred Sumner 6-242/+165 2021-12-16[http] Ensure errors from macros can see source codeGravatar Jarred Sumner 1-1/+19 2021-12-16[internal] disable debug workaroundGravatar Jarred Sumner 1-1/+1 2021-12-16[bundler] Fix edgecase where certain modules would load unbundled versionsGravatar Jarred Sumner 2-2/+17 2021-12-16[resolver] Change extension order based on import kindGravatar Jarred Sumner 1-1/+6 2021-12-16[resolver] When importing from an ES Module, prefer `.{m,c}{t,j}s`Gravatar Jarred Sumner 1-2/+28 2021-12-15wip fix live bindingsGravatar Jarred Sumner 6-418/+359 2021-12-15[JS transpiler] Simplify CommonJS interop callbackGravatar Jarred Sumner 2-67/+65 2021-12-15[JS transpiler] Ensure reserved words don't end up in nonUniqueIdentifier()Gravatar Jarred Sumner 2-0/+18 2021-12-15[JS Parser] Add regression testGravatar Jarred Sumner 1-0/+14 2021-12-15[JS Parser] Fix bug with template literals that create new scopes in the tag ...Gravatar Jarred Sumner 1-4/+4 2021-12-11Add a resource hint for preloading node_modules.bun and route asset in the fa...Gravatar Jarred Sumner 1-1/+43 2021-12-04[resolver] Do not throw on require()/import errors when they're caught (and i...Gravatar Jarred Sumner 2-53/+62 2021-11-26Bumpbun-v0.0.52Gravatar Jarred Sumner 1-1/+1 2021-11-25Fix occasional segfault when parsing JSON in http serverGravatar Jarred Sumner 1-2/+2 2021-11-25Revert "Merge pull request #70 from Jarred-Sumner/lithdew/picohttp-mimalloc"Gravatar Jarred Sumner 2-153/+132 2021-11-24mimalloc: patch malloc/freelithdew/picohttp-mimallocGravatar Kenta Iwasaki 2-7/+35 2021-11-24deps: add missing mimalloc dep to jsc bindings header generatorGravatar Kenta Iwasaki 2-2/+3 2021-11-24deps: build picohttp and mimalloc using zigGravatar Kenta Iwasaki 2-131/+123 2021-11-23update Next version on globalGravatar Jack Hanford 1-1/+1 2021-11-23Update build-idGravatar Jarred Sumner 1-1/+1 2021-11-23fix shallow routingGravatar Jack Hanford 1-4/+6 2021-11-23remove commentGravatar Jack Hanford 1-1/+0 2021-11-23add react-dom as devDepGravatar Jack Hanford 1-0/+1 2021-11-23stop installing textencoderGravatar Jack Hanford 3-2/+308 2021-11-23begin addressing more feedbackGravatar Jack Hanford 1-3/+3 2021-11-22remove .thenGravatar Jack Hanford 1-12/+3 2021-11-22another tryGravatar Jack Hanford 2-5/+1 2021-11-22add type fnsGravatar Jack Hanford 1-1/+4