From 524cb775b0ac5f93ba63f1c5cd6b1c0d0b42784c Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Wed, 16 Oct 2024 09:00:11 +0900 Subject: [PATCH] docs(cjs): add compilation caveats --- docs/dev-api/register-cjs.md | 6 ++++++ docs/dev-api/tsx-require.md | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/dev-api/register-cjs.md b/docs/dev-api/register-cjs.md index 612bbecd8..482bb38ed 100644 --- a/docs/dev-api/register-cjs.md +++ b/docs/dev-api/register-cjs.md @@ -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') diff --git a/docs/dev-api/tsx-require.md b/docs/dev-api/tsx-require.md index 958191d9a..24696ffdc 100644 --- a/docs/dev-api/tsx-require.md +++ b/docs/dev-api/tsx-require.md @@ -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 :::