Skip to content

Node built-in crypto imported in browser bundle — externalized by Vite with warning #608

@AlAnNuB

Description

@AlAnNuB

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions