Skip to content
This repository has been archived by the owner on Sep 9, 2021. It is now read-only.

build error: chunkFilename.replace is not a function at getDefaultChunkFilename #314

Open
sanderg93 opened this issue Apr 16, 2021 · 5 comments

Comments

@sanderg93
Copy link

  • Operating System: Ubuntu 20.04
  • Node Version: v14.16.1
  • NPM Version: 7.9.0
  • webpack Version: 5.30.0
  • worker-loader Version: v3.0.8

Expected Behavior

PdfjsLib library uses worker-loader to load pdf worker.

Expecting for webpack to build just fine.

Actual Behavior

Building gives the following error:

ERROR in ./node_modules/pdfjs-dist/build/pdf.worker.js (./node_modules/worker-loader/dist/cjs.js?esModule=false&filename=[name].js!./node_modules/pdfjs-dist/build/pdf.worker.js)
Module build failed (from ./node_modules/worker-loader/dist/cjs.js):
TypeError: chunkFilename.replace is not a function
at getDefaultChunkFilename (/node_modules/worker-loader/dist/utils.js:23:24)
at Object.pitch (
/node_modules/worker-loader/dist/index.js:61:108)

webpack compiled with 1 error

Code

"use strict";

var pdfjs = require("./build/pdf.js");
var PdfjsWorker = require("worker-loader?esModule=false&filename=[name].js!./build/pdf.worker.js");

if (typeof window !== "undefined" && "Worker" in window) {
  pdfjs.GlobalWorkerOptions.workerPort = new PdfjsWorker();
}

module.exports = pdfjs;

How Do We Reproduce?

Try to run the above code with the versions mentioned

@sanderg93
Copy link
Author

npm install pdfjs-dist@2.7.570 is used in this example

@alexander-akait
Copy link
Member

You don't need this loader for webpack v5, please look at this https://webpack.js.org/guides/web-workers/

@AdamRamberg
Copy link

I've got the exact same issue.

@alexander-akait when using that approach all my jest tests that are importing the module that uses that syntax explodes. It's due to this issue, which seems to be unfixable atm.

@alexander-akait
Copy link
Member

Let's open an issue in jest, because it is valid ESM

@AdamRamberg
Copy link

There is already a long-lived issue open that aims to solve this problem here. Haven't been diving into the specifics too much, but from my understanding this is not a problem that is easily fixed.

Just noticed that it seems to be fixed in jest 27 though. See this comment.

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

No branches or pull requests

3 participants