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

Uncaught SyntaxError: Unexpected token '<' in pdf.worker.js #994

Closed
4 tasks done
NaveenkumarMD opened this issue Apr 29, 2022 · 4 comments
Closed
4 tasks done

Uncaught SyntaxError: Unexpected token '<' in pdf.worker.js #994

NaveenkumarMD opened this issue Apr 29, 2022 · 4 comments
Labels
duplicate This issue or pull request already exists question Further information is requested

Comments

@NaveenkumarMD
Copy link

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

got an error as Failed to load pdf in the screen and the "Uncaught SyntaxError: Unexpected token '<' in pdf.worker.js" in the console.

Steps to reproduce

  • Install the package
            <Document 
                   file={require('../../Images/sample.pdf')}
                onLoadSuccess={onloadsuccess}
            >
                <Page pageNumber={pageNumber} />
            </Document>

Expected behavior

The pdf should be visible.

Actual behavior

The pdf is not rendered.

Additional information

No response

Environment

  • Browser (if applicable):
  • React-PDF version:
  • React version:
  • Webpack version (if applicable):
@NaveenkumarMD NaveenkumarMD added the bug Something isn't working label Apr 29, 2022
@Mitri45
Copy link

Mitri45 commented May 3, 2022

You have not mentioned what environment you are using, but assuming that you are using latest CRA application, which is using Webpack 5 under the hood, try to use different import for Document and Page components from react-pdf, like this:
import { Document, Page } from "react-pdf/dist/esm/entry.webpack";

Docs also provides other options of import paths, if you are using other bundler:

Bundler Entry file
Parcel 1 react-pdf/dist/esm/entry.parcel
Parcel 2 react-pdf/dist/esm/entry.parcel2
Webpack 4 react-pdf/dist/esm/entry.webpack
Webpack 5 react-pdf/dist/esm/entry.webpack5

@markivancho
Copy link

I could not reproduce it on my end, but our error tracking tool caught the similar error
I've recently switched to CRA-5 with React 18 and react-pdf/dist/esm/entry.webpack5
image

@wojtekmaj
Copy link
Owner

Duplicate of #97
See also #991, #680 and others.

@wojtekmaj wojtekmaj added duplicate This issue or pull request already exists question Further information is requested and removed bug Something isn't working labels May 4, 2022
@spogulis
Copy link

This worked but console throws a warning regarding source map:

DevTools failed to load source map: Could not parse content for http://127.0.0.1:8000/pdf.worker.js.map: Unexpected token < in JSON at position 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists question Further information is requested
Projects
None yet
Development

No branches or pull requests

5 participants