Skip to content
New issue

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

TypeError: key.split(...).at is not a function #1465

Closed
4 tasks done
Shawful opened this issue Apr 25, 2023 · 20 comments
Closed
4 tasks done

TypeError: key.split(...).at is not a function #1465

Shawful opened this issue Apr 25, 2023 · 20 comments
Labels
bug Something isn't working

Comments

@Shawful
Copy link

Shawful commented Apr 25, 2023

Before you start - checklist

  • I followed instructions in documentation written for my React-PDF version
  • I have checked if this bug is not already reported
  • I have checked if an issue is not listed in Known issues
  • If I have a problem with PDF rendering, I checked if my PDF renders properly in PDF.js demo

Description

Building into nextjs project here.

After running npm i react-pdf -P, and attempting npm run build, I experience the error in the title. Is there a previous version I should roll back to?

Steps to reproduce

install, build with nextjs

Expected behavior

expect a successful build

Actual behavior

Build error occurred
TypeError: key.split(...).at is not a function
at new KeyboardManager (/node_modules/pdfjs-dist/build/pdf.js:4213:43)

Additional information

No response

Environment

  • Browser (if applicable): chrome, latest
  • React-PDF version: 6.2.2
  • React version:17.0.2
  • Webpack version (if applicable): not using webpack
@Shawful Shawful added the bug Something isn't working label Apr 25, 2023
@Shawful
Copy link
Author

Shawful commented Apr 25, 2023

When rolling back to 5.7.0, I saw the issue was resolved, if that helps.

@Shawful Shawful closed this as completed Apr 25, 2023
@Shawful Shawful reopened this Apr 25, 2023
@berrytsukiii
Copy link

When rolling back to 5.7.0, I saw the issue was resolved, if that helps.

can't fix in vite application,sad

@wojtekmaj
Copy link
Owner

@berrytsukiii You should be able to get older versions working with Vite by following manual configuration process. I don't recommend that however, because I have almost no capacity to provide support for the latest version, let alone legacy ones.

@berrytsukiii
Copy link

berrytsukiii commented Apr 27, 2023

@wojtekmaj thks and according to this comment #1220 (comment) ,i have solved it temporarily。

@sebdec
Copy link

sebdec commented Apr 27, 2023

It happens on Safari v14.1.2 too (we don't use Vite)
it seems that it happens on version 6 react-pdf, not sure if it's a good idea to downgrade because this release fixes other important issues.

Environment

Browser (if applicable): Safari v14.1.2, v15
React-PDF version: 6.2.2
React version:17.0.2
Webpack version (if applicable): 4.46.0

@chongqiangchen
Copy link

install corejs and add this:

import 'core-js/features/array/at';

@sumit-velocis
Copy link

@chongqiangchen still the same error continues...

@chongqiangchen
Copy link

@chongqiangchen still the same error continues...

let me see how you write ?

@sumit-velocis
Copy link

app-pdf
error

"react-pdf": "^6.2.2",
"core-js": "^3.29.1"

You can see the attached screenshot.
let me know if i am doing anything wrong with it....

@chongqiangchen
Copy link

app-pdf error

"react-pdf": "^6.2.2", "core-js": "^3.29.1"

You can see the attached screenshot. let me know if i am doing anything wrong with it....

I write similarly to you, but I don't seem to have encountered your problem.

My component: https://github.com/chongqiangchen/unowai-frontend/blob/main/src/ui/widgets/pdf/index.tsx

Where I import the core: https://github.com/chongqiangchen/unowai-frontend/blob/main/src/pages/_app.tsx

@sumit-velocis
Copy link

app-pdf error
"react-pdf": "^6.2.2", "core-js": "^3.29.1"
You can see the attached screenshot. let me know if i am doing anything wrong with it....

I write similarly to you, but I don't seem to have encountered your problem.

My component: https://github.com/chongqiangchen/unowai-frontend/blob/main/src/ui/widgets/pdf/index.tsx

Where I import the core: https://github.com/chongqiangchen/unowai-frontend/blob/main/src/pages/_app.tsx

Error resolved after adding import 'core-js/features/array/at' at _app.js

Thanks for helping me out....

@jakec-dev
Copy link

I have the same issue and importing the core-js 'at' array helper to App.tsx didn't help.

Perhaps the 'at' helper should be removed? It seems a bit too new to be used in production yet. It's only supported in modern browsers at this stage.

@wojtekmaj
Copy link
Owner

wojtekmaj commented May 31, 2023

I'm not using it, PDF.js dependency is using it. There is an understandable push from the community to keep PDF.js up to date, but they also cut off from older browsers (2+ yrs) on a regular basis.

I have updated instructions in README yesterday and suggested using legacy worker if needed. Let me know if this works!

@asif-simform
Copy link

asif-simform commented Jun 6, 2023

Facing the same issue with the latest version 7.0.3 even using Legacy PDF.js worker.

image

@wojtekmaj
Copy link
Owner

@asif-simform Did you import 'core-js/features/array/at' as advised?

@wojtekmaj
Copy link
Owner

Since the documentation was updated to mention necessary polyfills and "base" compatibility table has been fixed I consider this issue resolved. If the documentation doesn't mention anything else it could, let me know.

@asif-simform
Copy link

@wojtekmaj

Yes, I've tried the same using import 'core-js/features/array/at' at the main index.js file. But still facing the same issue in safari.

Browser:- Safari Version 14.1.2 (16611.3.10.1.16)
Browser:- Safari Version 15.2 (17612.3.6.1.6)
image

@wojtekmaj
Copy link
Owner

wojtekmaj commented Jun 7, 2023

@asif-simform There's not a lot I can tell from this screenshot other than that Array.prototype.at is still undefined so either you're doing something incorrectly (e.g. loading core-js AFTER react-pdf) or perhaps some other tool is messing around with core-js imports.

I used core-js Array.prototype.at polyfill at the demo site and I got it working with Safari 15.2 just fine.

@Wangggym
Copy link

Wangggym commented Jun 9, 2023

image `core-js` cannot fix my question. I had to manually write a compatible writing method

@jjcoffee
Copy link

Just a heads up that this error also comes up from PDF.js itself now (rather than just the worker), so adding the polyfill is the only real solution. The core-js fix is working fine for me, it just needs to be imported before react-pdf.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

10 participants