From 55dad983472553537d9facc285825ab1bc7f3143 Mon Sep 17 00:00:00 2001 From: hillac Date: Wed, 31 Jul 2024 22:34:57 +1000 Subject: [PATCH] docs: add notes on ESM --- packages/frameworks-express/src/index.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/frameworks-express/src/index.ts b/packages/frameworks-express/src/index.ts index 80fee1581a..c6b9da24ca 100644 --- a/packages/frameworks-express/src/index.ts +++ b/packages/frameworks-express/src/index.ts @@ -121,6 +121,15 @@ * app.use("/protected", protected) * ``` * + * ## Notes on ESM + * @auth/express is ESM only. This means your package.json must contain `"type": "module"` and tsconfig.json should contain `"module": "NodeNext"` or `ESNext`. + * File imports must use the `.js` extension, e.g. `import { MyRouter } from "./my-router.js"`. + * + * Your dev server should either be run with [tsx](https://www.npmjs.com/package/tsx) with `tsx index.ts` (fast startup, with no type checking), or ts-node with 'node --loader ts-node/esm index.ts' (slower startup, but has type checking). + * + * While it is NOT recommended, if you wish to use @auth/express within a CommonJS project without migrating and making the above changes, you can run the dev server with tsx and may be able to compile with [pkgroll](https://tsx.is/compilation). + * Add '"name": "./dist/index.js"' or '"name": "./dist/index.mjs"' to your package.json and run 'pkgroll' to compile with both ESM and CommonJS support. For new projects it is recommended to just use ESM. + * * @module @auth/express */