Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

fix(erp): inline react-csv in SSR build only; dev server broke on its jsnext:main ESM entry (#1538)

Anshul sharma75627393db87
diff --git a/apps/erp/vite.config.ts b/apps/erp/vite.config.ts
index c12f54d12e..8caf89e75e 100644
--- a/apps/erp/vite.config.ts
+++ b/apps/erp/vite.config.ts
@@ -42,8 +42,15 @@ export default defineConfig(({ isSsrBuild, mode }) => {
* crashes on cold start with "Cannot find module 'react'". Bundling it
* inline resolves react/prop-types against the app's copies at build
* time, the same reason the react-* packages above are inlined.
+ *
+ * Build-only: react-csv also declares `"jsnext:main": "src/index.js"`,
+ * so when inlined in the dev server Vite picks the untranspiled ESM
+ * source, whose `import { func } from "prop-types"` fails under Node's
+ * CJS interop ("Named export 'func' not found"). In dev the CJS entry is
+ * externalized and `require`d directly, which works via pnpm's store.
*/
- "react-csv",
+
+ ...(isSsrBuild ? ["react-csv"] : []),
/**
* @react-three/fiber v8 (inlined via @carbon/viewer) default-imports
* its nested zustand v3, while the app uses zustand v5 (no default
@@ -93,7 +100,7 @@ export default defineConfig(({ isSsrBuild, mode }) => {
"@carbon/utils": path.resolve(__dirname, "../../packages/utils/src"),
"@carbon/form": path.resolve(
__dirname,
- "../../packages/form/src/index.tsx",
+ "../../packages/form/src/index.tsx"
),
},
},