The Docs.

Prim+RPC is in prerelease mode and may be unstable until official release.

Prevent Build Utility

This tool is in early stages and the interface is expected to change significantly.

The “Prevent Build” utility is a simple way of preventing a build using popular bundlers if server-specific code is accidentally imported. This is not required and often times is not needed as server and client are typically located in separate parts of a project but it can provide additional peace of mind that a developer doesn’t import server code in the client.

The utility is built with unplugin which means it can support the most popular bundlers used with JavaScript. Below is an example of how it may be used in Vite:

import path from "node:path"
import { defineConfig } from "vite"
import preventImport, { BuildModifyMethod } from "@doseofted/prim-rpc-tooling/build"
export default defineConfig({
	plugins: [
			name: path.join(__dirname, "server"),
			method: BuildModifyMethod.BuildTimeEmptyExport,

You may also use this plugin with Webpack or Rollup, among others.

This example blocks imports from the ./server directory by replacing the contents of the imported file with an empty export. There are several methods to block imports:

  • BuildModifyMethod.BuildTimeEmptyExport happens at build-time and replaces imported server code with an empty export
  • BuildModifyMethod.RunTimeProcessCheck happens at run-time and prepends a statement that throws an error if server code is imported by checking process.server. This is useful for flagging such errors in testing frameworks.
  • BuildModifyMethod.RunTimeWindowCheck also happens at run-time and is similar to the last option except instead of checking process.server it checks if the typeof window === "undefined".
Report an Issue

Prim+RPC: a project by Ted Klingenberg

Anonymous analytics collected with Ackee

Dose of Ted