worker-loader
worker-loader copied to clipboard
build error: chunkFilename.replace is not a function at getDefaultChunkFilename
- 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
npm install [email protected] is used in this example
You don't need this loader for webpack v5, please look at this https://webpack.js.org/guides/web-workers/
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.
Let's open an issue in jest, because it is valid ESM