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(build): stub `ws` so rhino3dm doesn't break the production build

Sidwebworksc060119c5394
diff --git a/apps/erp/app/ssr-shims/ws-stub.cjs b/apps/erp/app/ssr-shims/ws-stub.cjs
new file mode 100644
index 0000000000..5aa1897dc7
--- /dev/null
+++ b/apps/erp/app/ssr-shims/ws-stub.cjs
@@ -0,0 +1,21 @@
+/**
+ * Stub for the `ws` package. `rhino3dm`'s bundle carries a Node-only branch
+ * that does `require("ws")` for a WebSocket implementation, and it declares no
+ * dependencies at all — so `ws` is not resolvable from it.
+ *
+ * esbuild (Vite 7) left that alone; Rolldown (Vite 8) resolves the import
+ * statically while bundling the viewer's worker entry and fails the build.
+ * Nothing in this app uses `ws`, and the branch never runs in a browser or
+ * worker, so this only needs to load without throwing.
+ */
+"use strict";
+
+class WebSocketStub {
+ constructor() {
+ throw new Error("ws is not available in the browser build");
+ }
+}
+
+module.exports = WebSocketStub;
+module.exports.default = WebSocketStub;
+module.exports.WebSocket = WebSocketStub;
diff --git a/apps/erp/vite.config.ts b/apps/erp/vite.config.ts
index 6d37d0e20b..503811f62b 100644
--- a/apps/erp/vite.config.ts
+++ b/apps/erp/vite.config.ts
@@ -69,6 +69,14 @@ export default defineConfig(({ isSsrBuild, mode }) => {
* whole `konva` package — react-konva imports `konva/lib/Core.js`, etc.).
*/
canvas: path.resolve(__dirname, "app/ssr-shims/canvas-stub.cjs"),
+ /**
+ * `rhino3dm` (via @carbon/viewer) has a Node-only branch that
+ * `require("ws")`, but declares no dependencies, so `ws` is not
+ * resolvable from it. Rolldown (Vite 8) resolves that statically and
+ * fails the build; esbuild did not. Nothing here uses `ws` — stub it
+ * like `canvas` above.
+ */
+ ws: path.resolve(__dirname, "app/ssr-shims/ws-stub.cjs"),
// Directory (not index.ts) so subpath imports like
// `@carbon/utils/favicon` resolve to `src/favicon.ts`.
"@carbon/utils": path.resolve(__dirname, "../../packages/utils/src"),
diff --git a/apps/mes/app/ssr-shims/ws-stub.cjs b/apps/mes/app/ssr-shims/ws-stub.cjs
new file mode 100644
index 0000000000..5aa1897dc7
--- /dev/null
+++ b/apps/mes/app/ssr-shims/ws-stub.cjs
@@ -0,0 +1,21 @@
+/**
+ * Stub for the `ws` package. `rhino3dm`'s bundle carries a Node-only branch
+ * that does `require("ws")` for a WebSocket implementation, and it declares no
+ * dependencies at all — so `ws` is not resolvable from it.
+ *
+ * esbuild (Vite 7) left that alone; Rolldown (Vite 8) resolves the import
+ * statically while bundling the viewer's worker entry and fails the build.
+ * Nothing in this app uses `ws`, and the branch never runs in a browser or
+ * worker, so this only needs to load without throwing.
+ */
+"use strict";
+
+class WebSocketStub {
+ constructor() {
+ throw new Error("ws is not available in the browser build");
+ }
+}
+
+module.exports = WebSocketStub;
+module.exports.default = WebSocketStub;
+module.exports.WebSocket = WebSocketStub;
diff --git a/apps/mes/vite.config.ts b/apps/mes/vite.config.ts
index c00dfaa6bd..a06f5b0617 100644
--- a/apps/mes/vite.config.ts
+++ b/apps/mes/vite.config.ts
@@ -62,6 +62,14 @@ export default defineConfig(({ mode, isSsrBuild }) => {
* konva entry itself — the drawing pane needs the real browser build).
*/
canvas: path.resolve(__dirname, "app/ssr-shims/canvas-stub.cjs"),
+ /**
+ * `rhino3dm` (via @carbon/viewer) has a Node-only branch that
+ * `require("ws")`, but declares no dependencies, so `ws` is not
+ * resolvable from it. Rolldown (Vite 8) resolves that statically while
+ * bundling the viewer's worker entry and fails the build; esbuild did
+ * not. Nothing here uses `ws` — stub it like `canvas` above.
+ */
+ ws: path.resolve(__dirname, "app/ssr-shims/ws-stub.cjs"),
// Directory (not index.ts) so subpath imports like
// `@carbon/utils/favicon` resolve to `src/favicon.ts`.
"@carbon/utils": path.resolve(__dirname, "../../packages/utils/src"),