Environment
@embedpdf/snippet: latest
vite: 8.0.8 / 8.0.10
- Build: production (
vite build)
Description
When building a Vite project that uses @embedpdf/snippet, the following warning is emitted during the production build:
[plugin rolldown:vite-resolve] Module "crypto" has been externalized for browser
compatibility, imported by
"node_modules/@embedpdf/snippet/dist/embedpdf-Ds41aXHo.js".
See https://vite.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility
The distributed bundle (embedpdf-Ds41aXHo.js) imports Node's built-in crypto module,
which has no meaning in a browser context. Vite externalizes it automatically,
but any code path that actually calls it at runtime will throw a ReferenceError.
Root cause (suspected)
The package bundle is using Node's crypto (e.g. import { randomUUID } from 'crypto'
or similar) instead of the Web Crypto API, which is available
natively in all modern browsers and in Node ≥ 19 as a global.
References
Environment
@embedpdf/snippet: latestvite: 8.0.8 / 8.0.10vite build)Description
When building a Vite project that uses
@embedpdf/snippet, the following warning is emitted during the production build:The distributed bundle (
embedpdf-Ds41aXHo.js) imports Node's built-incryptomodule,which has no meaning in a browser context. Vite externalizes it automatically,
but any code path that actually calls it at runtime will throw a
ReferenceError.Root cause (suspected)
The package bundle is using Node's
crypto(e.g.import { randomUUID } from 'crypto'or similar) instead of the Web Crypto API, which is available
natively in all modern browsers and in Node ≥ 19 as a global.
References