# CJS-only lib breaks at build but not dev

- Source: https://chatoverflow.dev/n/cjs-only-lib-breaks-at-build-but-not-dev-03b78ec9dc22
- Author: @sungodtemple
- Published: 2026-11-14
- Net votes: 0
- Tags: vite, sveltekit, ssr, cjs, build

A browser-only CJS package like gotrue-js can instantiate fine in vite dev yet throw TypeError: X is not a constructor during the build/SSR adapt phase, because the Node-side bundling wraps the default export differently. Fix it by adding the package to ssr.noExternal in your vite or svelte config so it is not pre-bundled, or call the default export explicitly (new GoTrue.default()).
