mozilla / pdf.js

PDF Reader in JavaScript
https://mozilla.github.io/pdf.js/
Apache License 2.0
48.63k stars 10k forks source link

Module parse failed: Unexpected token (2413:45) #13273

Closed Danieliessen closed 3 years ago

Danieliessen commented 3 years ago

Attach (recommended) or Link to PDF file here:

Configuration:

Steps to reproduce the problem:

  1. Create a new vue application
  2. npm install pdfjs-dist
  3. Create a component that requests pdfjs-dist

    import pdfjsLib from "pdfjs-dist/build/pdf"; import { PDFViewer } from "pdfjs-dist/web/pdf_viewer"; import "pdfjs-dist/web/pdf_viewer.css";

What is the expected behavior? Well, it works.

What went wrong? Error:

Module parse failed: Unexpected token (2413:45)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See 
https://webpack.js.org/concepts#loaders   
|         intent: renderingIntent,
|         renderInteractiveForms: renderInteractiveForms === true,
>         annotationStorage: annotationStorage?.getAll() || null
|       });
|     }

 @ ./node_modules/cache-loader/dist/cjs.js??ref--12-0!./node_modules/babel-loader/lib!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader-v16/dist??ref--0-1!./src/components/PDFViewer.vue?vue&type=script&lang=js 3:0-44 6:0-8 30:23-31
 @ ./src/components/PDFViewer.vue?vue&type=script&lang=js
 @ ./src/components/PDFViewer.vue
 @ ./node_modules/cache-loader/dist/cjs.js??ref--12-0!./node_modules/babel-loader/lib!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader-v16/dist??ref--0-1!./src/App.vue?vue&type=script&lang=js
 @ ./src/App.vue?vue&type=script&lang=js
 @ ./src/App.vue
 @ ./src/main.js
 @ multi (webpack)-dev-server/client?http://192.168.1.139:8080&sockPath=/sockjs-node (webpack)/hot/dev-server.js ./src/main.js

 error  in ./node_modules/pdfjs-dist/web/pdf_viewer.js

Module parse failed: Unexpected token (895:20)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See 
https://webpack.js.org/concepts#loaders   
|     this._on(eventName, listener, {
|       external: true,
>       once: options?.once
|     });
|   }

Link to a viewer (if hosted on a site other than mozilla.github.io/pdf.js or as Firefox/Chrome extension): The application does not launch.

Snuffleupagus commented 3 years ago

Duplicate of #13200

Danieliessen commented 3 years ago

Solved by using 2.3.200 version...

thatkidarsene commented 2 years ago

Solved by using 2.3.200 version...

This worked thanks

rrrokhtar commented 1 year ago

On my side solved by using the legacy build

const pdfjsLib = require("pdfjs-dist/legacy/build/pdf.js");

pdfjs version: (3.2.146) node version: (14.21.3)

mt-sizilio commented 1 month ago

@rrrokhtar This lib is wonderful!!! 🥇 I discovered it recently and it helped me a lot, but unfortunately it stopped working recently. I can't get the URLs anymore.