-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Error: PDFViewer is a web specific API. #2599
Comments
Hello again, I think I have narrowed down the source of the problem somewhat. While I have been trying to solve this problem for a long time, I think the source of the entire problem is in the Because when I do not use this component, the error disappears. Node-console does not give any errors and the pdf can become dynamic. I need some help on the exact cause or solution to the problem. Do you have any solution or idea about the problem? @diegomura :( |
Try following instructions in https://react-pdf.org/compatibility. I'm not sure it's gonna help, but it won't hurt either :D |
Hello again, unfortunately the problem is not solved :( I wonder if the problem will be solved if I switch to the pure React project instead of Next. |
@gokhangunduz This is your issue: #2624 |
This will fix it for you. Use Next dynamic function to manually set server side rendering off and import it through that function instead of the regular import
instead of
|
I am grateful for your interest and comment. My problem is solved. Thank you so much bro. |
I also use Remix and can't make it work. // ParentComponent.tsx
import React, { lazy, Suspense } from "react";
const PdfPreview = lazy(async () => {
const module = await import("./PdfPreview.client");
return { default: module.default };
});
const ParentComponent = () => {
return (
<div>
<Suspense fallback={<div>Loading preview...</div>}>
<PdfPreview />
</Suspense>
</div>
);
} // PdfPreview.client.tsx
import { Document, Page, Text, View, StyleSheet, PDFViewer } from "@react-pdf/renderer";
const styles = StyleSheet.create({
page: {
flexDirection: "row",
},
section: {
margin: 10,
padding: 10,
flexGrow: 1,
},
});
const PdfPreview = () => {
return (
<PDFViewer>
<Document>
<Page size="A4" style={styles.page}>
<View style={styles.section}>
<Text>Section #1</Text>
</View>
<View style={styles.section}>
<Text>Section #2</Text>
</View>
</Page>
</Document>
</PDFViewer>
);
};
export default PdfPreview; |
That section is really of no help at all. Firstly, the latest (stable) version of Next.js is 14.1.0 so pointing to 14.1.1 isn't very helpful. Second, the other 'fix' doesn't work either. I would suggest that whole section on Next be replaced with the following solution posted above:
|
That works for me in "next": "14.1.2" |
@lou did you get it to work with Remix? I'm struggling with the same error. |
Is the problem that the page can't finish importing before the server finishes rendering? or PDFviewer couldn't be ssr I want to understand why it solves the problem.. |
The PDFViewer object SSR cannot run, hence the error thrown is this: PDFViewer is a web specific API. With the dynamic package in Next.js, the package to be imported is guaranteed to work on the CSR side. In this way, it can communicate with the web-APIs in the package to be imported. |
@nikita-pankratov I had the same "PDFViewer is a web specific API" when running my Remix project in production on Vercel, but not while developing locally. I didn't have the time to dig into why the node renderer was being imported instead of the dom renderer, but I was able to get around the issue by building the project locally and including react-pdf.browser.js:
Here's the component I use instead of using PDFViewer directly: PdfClientBrowser.client.tsx:
At some point, I'll see if I can debug properly, but this works for now. |
Yes that works, but there is a cache, I have app router and i imported the component that have complied pdf and inside that i have mark use client,
Then i have imported the whole pdf client component use dynamic import inside page.tsx file, then it got solved.
|
This is actually still not working for me even with |
For anyone still struggling on NextJS, this works for me. I use useEffect to simply conditionally render it when the page has loaded. "next": "^14.2.1",
export default Document |
@sunflowerm I was blessed by needing a solution and you posting it 11 hours ago. It works flawlessly. Thanks. |
bro is the hero |
Having this issue. anyone knows how to solve it?
|
Were u able to fix this? I'm facing same issue |
Yeah same thing. I copied the code exactly like in #2599 (comment). It only happens when trying to dynamically import the PDFViewer on next 14.2.15 |
For remix people, here is my version ( https://github.com/jamalsoueidan/cv-editor ) |
For Remix: Updating to |
Hello everyone, first of all I would like to thank everyone who contributed to this functional project. Coming to problem, I have a problem that I cannot solve;
In my Next.JS project, I get an error when I want to render my component named
<Document/>
in<PDFViewer/>
.Currently, I cannot perform dynamic operations on PDF.
After the reload process, the error is displayed on the node-console.
Note: I am currently doing Client Side Rendering of all components in my Next.JS project.
Preview.tsx;
Document.tsx;
Bash;
The text was updated successfully, but these errors were encountered: