diff --git a/build.js b/build.js index 2c6f659..4efb140 100644 --- a/build.js +++ b/build.js @@ -4,8 +4,37 @@ import fs from "fs-extra"; import childProcess from "child_process"; +import path from "path"; import pkg from "./package.json" with { type: "json" }; +/** + * Add .js extensions to relative imports in compiled JS files + * Required for Node.js ESM module resolution + */ +function addJsExtensions(dir) { + const files = fs.readdirSync(dir); + for (const file of files) { + const filePath = path.join(dir, file); + const stat = fs.statSync(filePath); + if (stat.isDirectory()) { + addJsExtensions(filePath); + } else if (file.endsWith('.js')) { + let content = fs.readFileSync(filePath, 'utf8'); + // Match: from "./something" or from '../something' (without .js extension) + content = content.replace( + /(from\s+['"])(\.\.?\/[^'"]+)(?