-
Notifications
You must be signed in to change notification settings - Fork 10k
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
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file #13200
Comments
Node version "12.16" |
Unfortunately "Vue", whatever that is, isn't something that the PDF.js contributors can support.
You probably need to use the correct type of build then, as explained at https://www.npmjs.com/package/pdfjs-dist/v/2.7.570?activeTab=readme
|
Same problem in React, after upgrading pdfjs-dist to 2.7.570 |
Same problem in React "pdfjs-dist": "^2.2.228" |
The answer has already been provided in #13200 (comment), so unless you explain what's unclear about it we cannot help!
That version is no longer supported, please find the supported versions at e.g. https://mozilla.github.io/pdf.js/getting_started/#download |
I locked the version to 2.2.228 instead of "^2.2.228" then this error didn't show any more. Kind of weird solution but it's effective. I'll find a new version to update current version, thank you answerd this question so quickly. 😁 |
As clearly mentioned #13200 (comment), that version is explicitly unsupported. |
The issue is, that in some version after 2.5 some lines with the optional chaining operator were added. This operator is not supported by webpack by default in its current version (as far as I know). Vue uses webpack (@sairamsunkara673M is using Vue and therefore webpack). So you may need an addiotional loader for the pdfjs-dist files. You could configure your webpack as follows:
This will use the babel plugin-proposal-optional-chaining plugin to compile files with optional chaining operators. Note that you need to have babel installed, in my project I have following babel packages:
Also this will probably extend your build time by a bit, since you need to parse the pdfjs-dist files with an additional loader. Some other suggestions? Edit:
|
If you import the ES5 version as indicated above there should be no optional chaining operators since those are not an ES5 feature. Moreover, we use Webpack 5 and that in turn uses Acorn 8 with according to webpack/webpack#10227 even supports optional chaining, so also here I don't see why this should not work. Just make sure you're using the latest PDF.js release since older ones may have been built with Webpack 4. |
I'm using react and I'm having this same problem with all the versions I have tried so far except for |
Since this is the first search result for the error message and the solution isn't in the thread... Symptom: The following error message shows up when you build.
Cause: your build configuration does not support option chaining. Likely something with webpack or babel. Solution 1: the quick fix is to use the // If this causes an error:
import * as PDFJSViewer from "pdfjs-dist/web/pdf_viewer";
import {getDocument } from "pdfjs-dist/build/pdf.js";
// use this instead:
import * as PDFJSViewer from "pdfjs-dist/legacy/web/pdf_viewer";
import {getDocument } from "pdfjs-dist/legacy/build/pdf.js"; Solution 2: Change your webpack configuration to support option chaining by installing |
@davidbstein's Solution 1 worked great for me as a Parcel user. Too bad these different versions aren't documented in any examples or the Webpack instructions. |
With vue-cli, it may be a bit more difficult to configure webpack. We succeeded by adding: In vue.config.js (https://cli.vuejs.org/core-plugins/babel.html):
in babel.config.js:
|
The |
I meet the same problem. Donnot use cnpm or yarn. Try to delete |
the same is the case for the core version. if you do not want to go through the hassle of upgrading webpack to include optional chaining, point to the legacy version which is included with the dist. the documentation omits that this exists
|
This here helped me resolve the issue |
Why not just revert the offending code? This issue is not resolved. These are all workarounds |
Agreed. I am using this for work, and there is not really adequate documentation. Some explicit fixes for React projects would be appreciated. |
For some reason, pdf js through CDN using const pdfjsLib = window['pdfjs-dist/build/pdf'] , pdfjsLib.GlobalWorkerOptions.workerSrc = '//mozilla.github.io/pdf.js/build/pdf.worker.js' worked without issue for a year, but about a month ago its starting to be a coinflip to work in Chrome... Trying to import * as pdfjsLib from 'pdfjs-dist/legacy/build/pdf.js' or even import * as pdfjs from 'pdfjs-dist' gives me the same error as above ..... Im about to hang myself ngl... |
The text was updated successfully, but these errors were encountered: