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

import * as pdfjsLib from 'pdfjs-dist/webpack'; needs .mjs #17319

Closed
tamuratak opened this issue Nov 22, 2023 · 0 comments · Fixed by #17320
Closed

import * as pdfjsLib from 'pdfjs-dist/webpack'; needs .mjs #17319

tamuratak opened this issue Nov 22, 2023 · 0 comments · Fixed by #17320
Labels

Comments

@tamuratak
Copy link
Contributor

Attach (recommended) or Link to PDF file here:

Configuration:

  • Web browser and its version: Firefox 120.0
  • Operating system and its version: macOS 13.6.1 22G313
  • PDF.js version: 5781e72 at the main branch
  • Is a browser extension: No

Steps to reproduce the problem:

  1. At examples/webpack
  2. Edit configs following the recommendation in README.md
  3. Run npm run build
  4. webpack throws an error.
  5. If I rewrite "pdfjs-dist/webpack" to "pdfjs-dist/webpack.mjs", no error occurs.

import * as pdfjsLib from "pdfjs-dist/webpack"; in README.md should be import * as pdfjsLib from "pdfjs-dist/webpack.mjs";

diff --git a/examples/webpack/main.mjs b/examples/webpack/main.mjs
index 9f9d7138b..2496885ac 100644
--- a/examples/webpack/main.mjs
+++ b/examples/webpack/main.mjs
@@ -3,14 +3,10 @@
 
 // Hello world example for webpack.
 
-import * as pdfjsLib from "pdfjs-dist";
+import * as pdfjsLib from "pdfjs-dist/webpack";
 
 const pdfPath = "../learning/helloworld.pdf";
 
-// Setting worker path to worker bundle.
-pdfjsLib.GlobalWorkerOptions.workerSrc =
-  "../../build/webpack/pdf.worker.bundle.js";
-
 // Loading a document.
 const loadingTask = pdfjsLib.getDocument(pdfPath);
 const pdfDocument = await loadingTask.promise;
diff --git a/examples/webpack/webpack.config.js b/examples/webpack/webpack.config.js
index 47301843c..b5c049340 100644
--- a/examples/webpack/webpack.config.js
+++ b/examples/webpack/webpack.config.js
@@ -6,8 +6,7 @@ const path = require("path");
 module.exports = {
   context: __dirname,
   entry: {
-    main: "./main.mjs",
-    "pdf.worker": "pdfjs-dist/build/pdf.worker.mjs",
+    main: "./main.mjs"
   },
   mode: "none",
   output: {
$  npm run build 

> webpack-pdf.js-example@0.2.0 build
> webpack

asset main.bundle.js 6.02 KiB [emitted] (name: main)
runtime modules 2.32 KiB 2 modules
./main.mjs 794 bytes [built] [code generated]

ERROR in ./main.mjs 6:0-47
Module not found: Error: Can't resolve 'pdfjs-dist/webpack' in '/Users/tamura/src/github/pdf.js/examples/webpack'
resolve 'pdfjs-dist/webpack' in '/Users/tamura/src/github/pdf.js/examples/webpack'
  Parsed request is a module
  using description file: /Users/tamura/src/github/pdf.js/examples/webpack/package.json (relative path: .)
    Field 'browser' doesn't contain a valid alias configuration
    resolve as module
      looking for modules in /Users/tamura/src/github/pdf.js/examples/webpack/node_modules
        existing directory /Users/tamura/src/github/pdf.js/examples/webpack/node_modules/pdfjs-dist
          using description file: /Users/tamura/src/github/pdf.js/examples/webpack/node_modules/pdfjs-dist/package.json (relative path: .)
            using description file: /Users/tamura/src/github/pdf.js/examples/webpack/node_modules/pdfjs-dist/package.json (relative path: ./webpack)
              /Users/tamura/src/github/pdf.js/examples/webpack/node_modules/pdfjs-dist/webpack doesn't exist
      /Users/tamura/src/github/pdf.js/examples/node_modules doesn't exist or is not a directory
      looking for modules in /Users/tamura/src/github/pdf.js/node_modules
        existing directory /Users/tamura/src/github/pdf.js/node_modules/pdfjs-dist
          using description file: /Users/tamura/src/github/pdf.js/node_modules/pdfjs-dist/package.json (relative path: .)
            using description file: /Users/tamura/src/github/pdf.js/node_modules/pdfjs-dist/package.json (relative path: ./webpack)
              /Users/tamura/src/github/pdf.js/node_modules/pdfjs-dist/webpack doesn't exist
      /Users/tamura/src/github/node_modules doesn't exist or is not a directory
      /Users/tamura/src/node_modules doesn't exist or is not a directory
      /Users/tamura/node_modules doesn't exist or is not a directory
      /Users/node_modules doesn't exist or is not a directory
      /node_modules doesn't exist or is not a directory

webpack 5.89.0 compiled with 1 error in 46 ms
$  npx webpack -v      

  System:
    OS: macOS 13.6.1
    CPU: (8) arm64 Apple M1
    Memory: 196.09 MB / 16.00 GB
  Binaries:
    Node: 18.18.2 - /opt/local/bin/node
    Yarn: 1.22.19 - ~/bin/yarn
    npm: 6.14.18 - ~/src/github/pdf.js/node_modules/.bin/npm
  Browsers:
    Chrome: 119.0.6045.159
    Safari: 17.1
  Packages:
    webpack: ^5.89.0 => 5.89.0 
    webpack-cli: ^5.1.4 => 5.1.4 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants