react-pdf icon indicating copy to clipboard operation
react-pdf copied to clipboard

Missing dependency on "pako"

Open texonidas opened this issue 2 years ago • 4 comments

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

  1. Install Yarn 2+ and enable Plug'n'Play in the repo
  2. Run yarn add @react-pdf/renderer
  3. Import @react-pdf/renderer in the root of the project
  4. Run the project

Expected behavior Successful project build

Desktop

  • OS: Windows
  • @react-pdf/renderer version: 3.1.12

texonidas avatar Jun 15 '23 23:06 texonidas

I just ran into this, I had to add the following to my .yarnrc.yml file:

packageExtensions:
  "@react-pdf/pdfkit@*":
    dependencies:
      "pako": "*"

Joshuabaker2 avatar Mar 12 '24 17:03 Joshuabaker2

I just ran into this, I had to add the following to my .yarnrc.yml file:

packageExtensions:
  "@react-pdf/pdfkit@*":
    dependencies:
      "pako": "*"

got this error:

"Cannot read properties of undefined (reading 'call')" when importing the package

zenricatlasopen avatar Mar 13 '24 08:03 zenricatlasopen

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(),
  ]
};

Joshuabaker2 avatar Mar 15 '24 23:03 Joshuabaker2

I just ran into this, I had to add the following to my .yarnrc.yml file:

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.

markcnunes avatar Aug 01 '24 10:08 markcnunes

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:

Image

@diegomura

ilia-os avatar Mar 25 '25 14:03 ilia-os