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

Not working with nextjs 13 and react 18 #231

Open
rico-c opened this issue Feb 12, 2023 · 4 comments
Open

Not working with nextjs 13 and react 18 #231

rico-c opened this issue Feb 12, 2023 · 4 comments

Comments

@rico-c
Copy link

rico-c commented Feb 12, 2023

It seems because react 18 not supporting reactElement, can anyone help me for a solution?

Error: 
  x Unexpected token `PdfLoader`. Expected jsx identifier
    ,-[/components/PdfViewer/index.tsx:14:1]
 14 | const PdfViewer:FC<any> = ({ id }: { id: string }) => {
 15 |   return (
 16 |     // <UIPdfContainer>
 17 |       <PdfLoader url={'https://arxiv.org/pdf/1708.08021.pdf'} beforeLoad={}>
    :        ^^^^^^^^^
 18 |             {(pdfDocument) => (
 19 |               <PdfHighlighter
 20 |                 pdfDocument={pdfDocument}
    `----

Caused by:
    Syntax Error
@kumaraswamyDR
Copy link

+1 I was also facing a similar issue

@joebutler2
Copy link
Contributor

Here is a PR I'm working on to support React 18 #232.

@wyneleaf
Copy link

wyneleaf commented Aug 7, 2023

Hi I just spinned up a fresh nextjs project but I am getting another error than the mentioned above.

I am using the latest nextjs (13.4.1) and react (18.2.0) to try it since the PR mentioned by @joebutler2 which now has been merged into react-pdf-highlighter 6.1.0.

All usages of the library in my code goes through an internal "proxy import" I have made in a file named /app/@react-pdf-highligter.ts which looks like this...

'use client'
export * from 'react-pdf-highlighter';

So I have modified all example code supplied in this repo (i.e. in App.tsx, Sidebar.tsx etc) to use ...

import type { IHighlight, NewHighlight } from "@/app/@react-pdf-highlighter";

This does however give me the following error:

File was processed with these loaders:
 * ./node_modules/.pnpm/next@13.4.13_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/build/webpack/loaders/next-app-loader.js
You may need an additional loader to handle the result of these loaders.
|   }
|         }],
> react-pdf-highlighter: [
|           '__DEFAULT__',
|           {},
    at <unknown> (:3000/File was processed with these loaders:)
    at handleParseError (/Users/ew/Projects/test-pdf-highlighter/node_modules/.pnpm/next@13.4.13_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/compiled/webpack/bundle5.js:28:401816)
    at <unknown> (/Users/ew/Projects/test-pdf-highlighter/node_modules/.pnpm/next@13.4.13_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/compiled/webpack/bundle5.js:28:403563)
    at processResult (/Users/ew/Projects/test-pdf-highlighter/node_modules/.pnpm/next@13.4.13_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/compiled/webpack/bundle5.js:28:399258)
    at <unknown> (/Users/ew/Projects/test-pdf-highlighter/node_modules/.pnpm/next@13.4.13_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/compiled/webpack/bundle5.js:28:400319)
    at <unknown> (/Users/ew/Projects/test-pdf-highlighter/node_modules/.pnpm/next@13.4.13_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/compiled/loader-runner/LoaderRunner.js:1:8727)
    at iterateNormalLoaders (/Users/ew/Projects/test-pdf-highlighter/node_modules/.pnpm/next@13.4.13_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/compiled/loader-runner/LoaderRunner.js:1:5565)
    at iterateNormalLoaders (/Users/ew/Projects/test-pdf-highlighter/node_modules/.pnpm/next@13.4.13_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/compiled/loader-runner/LoaderRunner.js:1:5650)
    at <unknown> (/Users/ew/Projects/test-pdf-highlighter/node_modules/.pnpm/next@13.4.13_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/compiled/loader-runner/LoaderRunner.js:1:5879)
    at <unknown> (/Users/ew/Projects/test-pdf-highlighter/node_modules/.pnpm/next@13.4.13_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/compiled/loader-runner/LoaderRunner.js:1:4271)

Anyone have any clues on how to proceed?

@wyneleaf
Copy link

wyneleaf commented Aug 8, 2023

Seems to have been a temporary error, that later disappeared.

Instead I got the error from pdfjs dist about the missing canvas module so I then used dynamic imports. Basically taking the entire https://github.com/agentcooper/react-pdf-highlighter/blob/main/example/src/App.tsx (and its sub components) in this repo and moved it to my own local component folder in my nextjs project /components/docviewer/DocViewer and then wrapped it in a dynamic import in a DynamicDocViewer.tsx in the same folder...

'use client'

import dynamic from "next/dynamic";

const DynamicDocViewer = dynamic(
    (() => {
        if (typeof window !== 'undefined') {
            return import('./DocViewer');
        }
    }) as any,
    { ssr: false } // This will prevent the module from being loaded on the server-side
);

export default DynamicDocViewer;

...then I could use it from my /app/page.tsx and render it like any other component...

import DynamicDocViewer from "@/components/docviewer/DynamicDocViewer";
...
<DynamicDocViewer />

...and then it was working fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants