Skip to content

Commit

Permalink
docs(cjs): add compilation caveats
Browse files Browse the repository at this point in the history
  • Loading branch information
privatenumber committed Oct 16, 2024
1 parent 7f8a051 commit 524cb77
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions docs/dev-api/register-cjs.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

The CommonJS Register API allows you to manually register the enhancement at runtime. But note, this only affects CommonJS modules (`.cjs`/`.cts`, and `.js`/`.ts` when `package.json#type` is unset or `commonjs`).

::: warning Caveats

- `import()` calls in the loaded files are not enhanced because they're handled by Node's ESM hook. Use with the [`ESM Register API`](/dev-api/register-esm).
- Because it compiles ESM syntax to run in CommonJS mode, top-level await is not supported
:::

## Usage
```js
const tsx = require('tsx/cjs/api')
Expand Down
2 changes: 1 addition & 1 deletion docs/dev-api/tsx-require.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Note, the current file path must be passed in as the second argument to resolve

::: warning Caveats

- `import()` calls in the loaded files are not enhanced.
- `import()` calls in the loaded files are not enhanced. Use [`tsImport()`](/dev-api/ts-import) instead.
- Because it compiles ESM syntax to run in CommonJS mode, top-level await is not supported
:::

Expand Down

0 comments on commit 524cb77

Please sign in to comment.