diff options
author | 2023-09-08 11:18:52 -0700 | |
---|---|---|
committer | 2023-09-08 11:18:52 -0700 | |
commit | 989dd92ea8bf249cf7e32962d587a35d7b0c1277 (patch) | |
tree | e69b890941ca7e95fa293c20d5601cb31c8832ea | |
parent | 9e3cabc540149eae31cffff104a3642792a2ae79 (diff) | |
download | bun-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.
-rw-r--r-- | docs/runtime/modules.md | 14 |
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 |