Skip to content

ESM contains server code, doesn't provide named exports #1317

@thekevinbrown

Description

@thekevinbrown

Describe the bug
When using Vite to package a React app, we hit some issues because:

  1. The ESM that @react-pdf/renderer provides doesn't seem to provide the same exports as the CJS module.
  2. There is server code included in the ESM, but this library is a browser module.

To Reproduce
You can reproduce with this repository: https://github.com/thekevinbrown/vite-react-pdf-reproduction

Expected behavior
I expected React PDF to be able to be bundled and used in an ESM context.

Screenshots

Uncaught ReferenceError: global is not defined
    at node_modules/blob/index.js (@react-pdf_renderer.js:554)
    at __require (chunk-KVFJW2XH.js:12)
    at node_modules/blob-stream/index.js (@react-pdf_renderer.js:616)
    at __require (chunk-KVFJW2XH.js:12)
    at @react-pdf_renderer.js:126368

Desktop (please complete the following information):

  • OS: MacOS
  • Browser: Chrome
  • React-pdf version: "@react-pdf/renderer": "^2.0.12",

Additional Notes

An issue was logged with Vite here: vitejs/vite#3405

This may be related to this issue as well: #1029

I'd be happy to help with a PR if one is welcome, just wanted to check to ensure I wasn't duplicating effort and that this was something you'd accept a PR for.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions