From 35acef607165f6f9bab323b960626da740e64eee Mon Sep 17 00:00:00 2001 From: Amanuel Sisay Date: Wed, 7 Oct 2026 09:23:24 +0200 Subject: [PATCH] fix: Compile themeable package to CommonJS so it is importable The themeable entry point `theming.js` is a copy of the one in cloudscape-design/components, which compiles it to CommonJS. This repo compiled it with `module: ESNext`, so the emitted file kept `import` syntax and Node loaded it as ESM, where `__dirname` is not defined: ReferenceError: __dirname is not defined in ES module scope Mirror the components repo: compile `src-themeable` to CommonJS and point the `exports` entry at the file via `default`, so both `import` and `require` resolve to the CJS build. Also drop `designTokensTemplateDir`: chat components reuse the core design tokens and ship no `template-tokens` directory, so the build failed with ENOENT once the import succeeded. The option is optional in theming-build; the design-tokens output is still generated from the preset. --- scripts/package-json.js | 2 +- src-themeable/theming.ts | 4 ++-- tsconfig.src-themeable.json | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/package-json.js b/scripts/package-json.js index 42d55c7..1db735e 100644 --- a/scripts/package-json.js +++ b/scripts/package-json.js @@ -26,7 +26,7 @@ function themablePackage() { exports: { ".": { types: "./theming.d.ts", - import: "./theming.js", + default: "./theming.js", }, }, }); diff --git a/src-themeable/theming.ts b/src-themeable/theming.ts index 79f5aa0..04738f8 100644 --- a/src-themeable/theming.ts +++ b/src-themeable/theming.ts @@ -10,7 +10,6 @@ import { preset, TypedOverride } from "./internal/template/internal/generated/th const internalDir = join(__dirname, "./internal"); const scssDir = join(internalDir, "./scss"); const templateDir = join(internalDir, "./template"); -const designTokensTemplateDir = join(internalDir, "./template-tokens"); export type Theme = TypedOverride; export interface BuildThemedComponentsParams { @@ -25,9 +24,10 @@ export function buildThemedComponents({ theme, outputDir, baseThemeId }: BuildTh preset, baseThemeId, componentsOutputDir: join(outputDir, "components"), + // The chat components reuse the core design tokens and ship no + // design-tokens template, so designTokensTemplateDir is omitted. designTokensOutputDir: join(outputDir, "design-tokens"), templateDir, - designTokensTemplateDir, scssDir, }); } diff --git a/tsconfig.src-themeable.json b/tsconfig.src-themeable.json index 9863673..96a58f6 100644 --- a/tsconfig.src-themeable.json +++ b/tsconfig.src-themeable.json @@ -2,8 +2,8 @@ "compilerOptions": { "lib": ["es2019", "dom", "dom.iterable"], "target": "ES2019", - "module": "ESNext", - "moduleResolution": "nodenext", + "module": "CommonJS", + "moduleResolution": "node16", "rootDir": "src-themeable", "declaration": true, "incremental": true,