skip to content
Skill Issue Dev | Dax the Dev
search
↑ github.com ← all notes

ESM crypto import in Vite — stop using `require()`

Vite 5 with "type": "module" rejects require("crypto"). Symptom: dev server boots, prod build silently drops the crypto import, runtime crashes on first signature verify. No warning at build time.

Fix: import { createHash } from "node:crypto" (the node: prefix matters too — without it, the bundler tries to find a polyfill called “crypto” and ships ~120KB of extra code). The node: prefix tells Vite to keep the import as a node-builtin and not try to bundle it.