Hopding / pdf-lib

Create and modify PDF documents in any JavaScript environment
https://pdf-lib.js.org
MIT License
6.6k stars 635 forks source link

"invalid distance too far back" error when running on Next.js 14 with Turbopack #1619

Open yan3321 opened 3 months ago

yan3321 commented 3 months ago

What were you trying to do?

Trying to generate a PDF

How did you attempt to do it?

Visiting an API route under the app directory in Next.js 14 while running the dev server with Turbopack

What actually happened?

Any attempts to generate the PDF result in an "invalid distance too far back" error

What did you expect to happen?

The PDF should be generated successfully

How can we reproduce the issue?

Install pdf-lib, Next.js 14, run the Turbopack dev server with next dev --turbo

Version

1.17.1

What environment are you running pdf-lib in?

Node

Checklist

Additional Notes

While I do not have a SSCCE, I have eventually tracked this error down to the pako library with is apparently a port of zlib. pdf-lib and its dependencies are relying on an older v1 version.

By manually overriding pako to v2 (using pnpm in my case) in package.json:

"pnpm": {
    "overrides": {
      "pako": "^2.1.0"
    }
  }

For my specific implementation, I no longer run into any issues with the PDF generation and it works as expected. As an alternative, the normal Webpack dev server can still be used with no problems.

SulTanvai0 commented 2 months ago

the issue is here "next dev --turbo" turbo isn't stabel yet try "dev": "next dev" $- npm run dev