From 989dd92ea8bf249cf7e32962d587a35d7b0c1277 Mon Sep 17 00:00:00 2001 From: Dan Fabulich Date: Fri, 8 Sep 2023 11:18:52 -0700 Subject: 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. --- docs/runtime/modules.md | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'docs/runtime/modules.md') 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 -- cgit v1.2.3