I'm currently trying to add export to PDF functionality to my React application using jsPdf. My application uses Webpack5, which I know has removed a number of polyfills that existed in Webpack4. I originally encountered a buffer is not defined error when trying to save the PDF, which I resolved by adding the buffer polyfill. However, since then I am receiving a new error when trying to save the PDF:
Uncaught (in promise) TypeError: r.writeFileSync is not a function
at I.v.save (jspdf.js:13845:1)
Has anyone seen this error before and been able to resolve? I think it may be that I need to polyfill more node modules, but cannot identify which one will resolve this.
I have tried installing a number of packages such as: "process": "^0.11.10" "write-to-file-webpack": "^1.0.6" (which I believe now is only for Webpack4) "stream-browserify": "^3.0.0" Updating webpack.config.js file:
fallback: {
stream: require.resolve("stream-browserify"),
buffer: require.resolve("buffer"),
process: require.resolve('process/browser'),
},
plugins: [
process: "process/browser",
Buffer: ["buffer", "Buffer"],
],
Also tried adding the following to fallback from reading issues others have experienced with Webpack5: "fs": false, "tls": false, "net": false, "path": false, "zlib": false, "http": false, "https": false, "stream": false, "crypto": false,
I am still unable to identify what will resolve the r.writeFileSync is not a function. Anyone have any ideas or suggestions? Thanks in advance.