From 4dc4efc3338126d831cdd86e9a1b1c2b5b713836 Mon Sep 17 00:00:00 2001 From: Tim Neutkens Date: Mon, 4 Mar 2024 09:37:42 +0100 Subject: [PATCH] Ensure ESM files import including the extension Currently it causes a resolving error in e.g. Node.js, Turbopack, etc. that correctly support ESModules. --- packages/core/rsc/provider.tsx | 2 +- packages/core/rsc/rsc-client.ts | 2 +- packages/core/rsc/{rsc-shared.ts => rsc-shared.mts} | 0 packages/core/tsup.config.ts | 3 ++- 4 files changed, 4 insertions(+), 3 deletions(-) rename packages/core/rsc/{rsc-shared.ts => rsc-shared.mts} (100%) diff --git a/packages/core/rsc/provider.tsx b/packages/core/rsc/provider.tsx index 92f68be..66d2cb0 100644 --- a/packages/core/rsc/provider.tsx +++ b/packages/core/rsc/provider.tsx @@ -1,7 +1,7 @@ // This file provides the AI context to all AI Actions via AsyncLocalStorage. import * as React from 'react'; -import { InternalAIProvider } from './rsc-shared'; +import { InternalAIProvider } from './rsc-shared.mjs'; import { withAIState, getAIStateDeltaPromise, diff --git a/packages/core/rsc/rsc-client.ts b/packages/core/rsc/rsc-client.ts index f2027b7..a977824 100644 --- a/packages/core/rsc/rsc-client.ts +++ b/packages/core/rsc/rsc-client.ts @@ -4,4 +4,4 @@ export { useAIState, useActions, useSyncUIState, -} from './rsc-shared'; +} from './rsc-shared.mjs'; diff --git a/packages/core/rsc/rsc-shared.ts b/packages/core/rsc/rsc-shared.mts similarity index 100% rename from packages/core/rsc/rsc-shared.ts rename to packages/core/rsc/rsc-shared.mts diff --git a/packages/core/tsup.config.ts b/packages/core/tsup.config.ts index 4c86c14..411dfb4 100644 --- a/packages/core/tsup.config.ts +++ b/packages/core/tsup.config.ts @@ -72,7 +72,8 @@ export default defineConfig([ }, // RSC APIs - shared client { - entry: ['rsc/rsc-shared.ts'], + // Entry is `.mts` as the entrypoints that import it will be ESM so it needs exact imports that includes the `.mjs` extension. + entry: ['rsc/rsc-shared.mts'], outDir: 'rsc/dist', format: ['esm'], external: ['react', 'zod'],