diff --git a/package.json b/package.json index 9b51765..8bf24d4 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,8 @@ "build:dev": "vite build --mode development", "preview": "vite preview", "lint": "eslint .", - "format": "prettier --write ." + "format": "prettier --write .", + "postinstall": "node scripts/patch-lovable-config.cjs" }, "dependencies": { "@cloudflare/vite-plugin": "^1.25.5", diff --git a/scripts/patch-lovable-config.cjs b/scripts/patch-lovable-config.cjs new file mode 100644 index 0000000..6ef5953 --- /dev/null +++ b/scripts/patch-lovable-config.cjs @@ -0,0 +1,37 @@ +// Patches @lovable.dev/vite-tanstack-config to prefer the ESM entrypoint +// (dist/index.js) over the CJS one (dist/index.cjs) for import contexts. +// Required for Node.js >=22.12 compat — the CJS file does require("vite"), +// which is ESM-only, causing ERR_REQUIRE_CYCLE_MODULE. +const fs = require("fs"); +const path = require("path"); + +const pkgPath = path.resolve( + __dirname, + "..", + "node_modules", + "@lovable.dev", + "vite-tanstack-config", + "package.json", +); + +if (!fs.existsSync(pkgPath)) { + console.warn("[patch-lovable-config] package not found — skipping"); + process.exit(0); +} + +const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8")); + +if (pkg.exports) { + console.log("[patch-lovable-config] exports already present — nothing to do"); + process.exit(0); +} + +pkg.exports = { + ".": { + import: "./dist/index.js", + require: "./dist/index.cjs", + }, +}; + +fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + "\n"); +console.log("[patch-lovable-config] added exports field to prefer ESM entrypoint"); diff --git a/src/components/Commands.tsx b/src/components/Commands.tsx index 93266cd..083fea2 100644 --- a/src/components/Commands.tsx +++ b/src/components/Commands.tsx @@ -63,12 +63,12 @@ export const Commands = () => {