We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Describe the bug
When building react-pdf in ESM mode, you may encounter an error:
__dirname is not defined in ES module scope
This is because yoga-layout uses __dirname in their code. This has already been reported to them: facebook/yoga#1559
__dirname
To work around this issue, for now, consider using inject option in esbuild:
inject
cjs-shim.ts
import { createRequire } from 'node:module'; import path from 'node:path'; import url from 'node:url'; globalThis.require = createRequire(import.meta.url); globalThis.__filename = url.fileURLToPath(import.meta.url); globalThis.__dirname = path.dirname(__filename);
esbuild.ts
await esbuild.build({ // … inject: ['cjs-shim.ts'], // … });
If you're not using esbuild, you may manually import the cjs-shim.ts file BEFORE react-pdf is loaded.
The text was updated successfully, but these errors were encountered:
Added to official documentation in diegomura/react-pdf-site#128.
Sorry, something went wrong.
@wojtekmaj, I'm having this issue using react-pdf on electron-vite. Could you tell more about how to workaround this issue?
Successfully merging a pull request may close this issue.
Describe the bug
When building react-pdf in ESM mode, you may encounter an error:
This is because yoga-layout uses
__dirname
in their code. This has already been reported to them: facebook/yoga#1559To work around this issue, for now, consider using
inject
option in esbuild:cjs-shim.ts
esbuild.ts
If you're not using esbuild, you may manually import the
cjs-shim.ts
file BEFORE react-pdf is loaded.The text was updated successfully, but these errors were encountered: