You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
@react-pdf/font started to depend on pdfkit@0.20.1 and triggers a TypeError: Invalid URL #3532
Describe the bug
Upgrading @react-pdf/font from 4.0.9 to 4.1.0 or 4.1.1 caused a TypeError: Invalid URL
To Reproduce
It is difficult for me to share a reproducible code snippet / example.
In our project, @react-pdf/font is a dependency of @react-pdf/renderer@4.6.0(react@19.2.8) and @react-pdf/types@2.13.1.
We use TypeScript, pnpm, and our code is transpiled using ESBuild.
When invoking Node on the transpiled JS bundle, we get this stracktrace:
TypeError: Invalid URL
at new URL (node:internal/url:840:25)
at Object.<anonymous> (/app/node_modules/.pnpm/pdfkit@0.20.1/node_modules/pdfkit/lib/mixins/pdfa.js:3:33)
at Module._compile (node:internal/modules/cjs/loader:1871:14)
at Object..js (node:internal/modules/cjs/loader:2002:10)
at Module.load (node:internal/modules/cjs/loader:1594:32)
at Module._load (node:internal/modules/cjs/loader:1396:12)
at wrapModuleLoad (node:internal/modules/cjs/loader:255:19)
at Module.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:154:5)
at node:internal/main/run_main_module:33:47
changed the title [-]@react-pdf/font started to depend on pdfkit@0.20.1 and triggers a TypeError: Invalid URL for our use case[/-][+]@react-pdf/font started to depend on pdfkit@0.20.1 and triggers a TypeError: Invalid URL[/+]on Aug 26, 2026
We hit the same error after upgrading @react-pdf/renderer from 4.3.2 to 4.5.1.
The failure is still there with the current pdfkit master (0.20.2), so newer renderer versions are affected too.
Here is a minimal reproduction and some details that may help.
Reproduction
Two lines of code, bundled with esbuild for Node (CommonJS output, which is the default when format is not set):
@react-pdf/font imports pdfkit. Since pdfkit 0.20, the package resolves the import condition for Node to js/pdfkit.node.mjs. That file uses import.meta.url at the top level:
TypeError [ERR_INVALID_ARG_VALUE]: The argument 'filename' must be a file URL object, file URL string, or absolute path string. Received undefined
This is why the error shows up on the first request in AWS Lambda and similar setups, where the code is usually bundled to CommonJS with esbuild or webpack. @react-pdf/renderer 4.3.x did not have this problem because @react-pdf/font used the @react-pdf/pdfkit fork, which did not rely on import.meta.
Possible directions
In pdfkit: compute ICC_PROFILE_PATH lazily inside _addColorOutputIntent (it is only needed for PDF/A output), and fall back to the ambient require when import.meta.url is undefined, instead of calling createRequire at module load. Both changes are small and keep the ESM build working as it is today.
In @react-pdf/font: import the CommonJS entry of pdfkit (pdfkit/js/pdfkit.js) or document that consumers must bundle as ESM.
Workarounds we found for now: pin @react-pdf/renderer to 4.3.2, or bundle with --format=esm.
Happy to open a PR on the pdfkit side if that approach is acceptable.
Activity
[-]@react-pdf/font started to depend on pdfkit@0.20.1 and triggers a TypeError: Invalid URL for our use case[/-][+]@react-pdf/font started to depend on pdfkit@0.20.1 and triggers a TypeError: Invalid URL[/+]alainrk commentedon Sep 10, 2026
We hit the same error after upgrading
@react-pdf/rendererfrom 4.3.2 to 4.5.1.The failure is still there with the current
pdfkitmaster (0.20.2), so newer renderer versions are affected too.Here is a minimal reproduction and some details that may help.
Reproduction
Two lines of code, bundled with esbuild for Node (CommonJS output, which is the default when
formatis not set):Result: the bundle throws at module load, before any document is rendered.
Versions: Node 24.13, esbuild 0.28.0 (also reproduced with 0.27.2),
@react-pdf/renderer4.5.1,@react-pdf/font4.1.2,pdfkit0.20.1.What happens
@react-pdf/fontimportspdfkit. Sincepdfkit0.20, the package resolves theimportcondition for Node tojs/pdfkit.node.mjs. That file usesimport.meta.urlat the top level:When esbuild produces a CommonJS bundle,
import.metais replaced with an empty object, so the base URL isundefinedandnew URL()throws.There is a second top-level use in the same file, so fixing the ICC line alone is not enough. If the URL line is patched, the bundle then fails on:
This is why the error shows up on the first request in AWS Lambda and similar setups, where the code is usually bundled to CommonJS with esbuild or webpack.
@react-pdf/renderer4.3.x did not have this problem because@react-pdf/fontused the@react-pdf/pdfkitfork, which did not rely onimport.meta.Possible directions
pdfkit: computeICC_PROFILE_PATHlazily inside_addColorOutputIntent(it is only needed for PDF/A output), and fall back to the ambientrequirewhenimport.meta.urlis undefined, instead of callingcreateRequireat module load. Both changes are small and keep the ESM build working as it is today.@react-pdf/font: import the CommonJS entry ofpdfkit(pdfkit/js/pdfkit.js) or document that consumers must bundle as ESM.Workarounds we found for now: pin
@react-pdf/rendererto 4.3.2, or bundle with--format=esm.Happy to open a PR on the
pdfkitside if that approach is acceptable.wangzuo commentedon Oct 16, 2026
better to pin
@react-pdf/fontwith 4.0