Missing dependency on "pako"
Describe the bug While using @react-pdf/renderer in a project with Yarn Plug'n'Play enabled I received several warnings about "pako":
The Yarn Plug'n'Play manifest forbids importing "pako" here because it's not listed as a
dependency of this package:
To Reproduce
- Install Yarn 2+ and enable Plug'n'Play in the repo
- Run
yarn add @react-pdf/renderer - Import @react-pdf/renderer in the root of the project
- Run the project
Expected behavior Successful project build
Desktop
- OS: Windows
- @react-pdf/renderer version: 3.1.12
I just ran into this, I had to add the following to my .yarnrc.yml file:
packageExtensions:
"@react-pdf/pdfkit@*":
dependencies:
"pako": "*"
I just ran into this, I had to add the following to my
.yarnrc.ymlfile:packageExtensions: "@react-pdf/pdfkit@*": dependencies: "pako": "*"
got this error:
"Cannot read properties of undefined (reading 'call')" when importing the package
got this error:
"Cannot read properties of undefined (reading 'call')" when importing the package
That's because the EventEmitter isn't added in correctly, you have to also add the following to your vite config file via a polyfill:
const nodePolyfills = require("rollup-plugin-node-polyfills");
module.exports = {
resolve: {
alias: {
events: require.resolve("rollup-plugin-node-polyfills/polyfills/events"),
},
},
plugins: [
nodePolyfills(),
]
};
I just ran into this, I had to add the following to my
.yarnrc.ymlfile:packageExtensions: "@react-pdf/pdfkit@*": dependencies: "pako": "*"
Thanks, @Joshuabaker2 , for sharing your fix. I had a similar problem with Pnpm.
I’ve been using @react-pdf/renderer without any issues, just adding it to package.json worked fine. But after I added @flatfile/react to my project, I started getting an error about not finding pako:
"Module not found: Package path ./lib/zlib/zstream.js is not exported from package" https://github.com/diegomura/react-pdf/issues/2795
Your suggestion to add pako to packageExtensions fixed the issue for me (I didn’t need a polyfill).
Here’s how you can fix it with Pnpm:
package.json
"pnpm": {
"packageExtensions": {
"@react-pdf/pdfkit@*": {
"dependencies": {
"pako": "*"
}
}
}
}
According to Pnpm’s documentation:
The packageExtensions field lets you add extra information to package definitions. For example, if react-redux should have react-dom as a peer dependency but doesn’t, you can add it using packageExtensions. https://pnpm.io/next/package_json#pnpmpackageextensions
It made me wonder why @react-pdf/pdfkit doesn’t include pako as a dependency if it uses it.
It’s also strange that the error only showed up after adding @flatfile/react.
But at least it is good to know we can use packageExtensions to fix such issues.
Sooo should we add "pako" as a dependency?
It is wrong that "pako" is not listed as a dependency: strict tools like yarn modern succesfully catch this
I see that this is not the direct dependency, but rather comes from browserify-zlib.
I dont think lines 39-47 of rollup.config.js affects it as deflate.js is not present there (but present on my screenshot)
I've encountered similar issue today:
@diegomura