craco icon indicating copy to clipboard operation
craco copied to clipboard

react-pdf webpack config not working

Open rawedit opened this issue 4 years ago • 2 comments

There's an issue with react-pdf v2 and webpack v5, I've installed the required packages and have overridden the webpack settings in the 'craco.config.js' file as recommend by the react-pdf docs:

npm install process browserify-zlib stream-browserify util buffer assert

const webpack = require("webpack");

module.exports = { resolve: { fallback: { module: "empty", dgram: "empty", dns: "mock", fs: "empty", http2: "empty", net: "empty", tls: "empty", child_process: "empty", process: require.resolve("process/browser"), zlib: require.resolve("browserify-zlib"), stream: require.resolve("stream-browserify"), util: require.resolve("util"), buffer: require.resolve("buffer"), asset: require.resolve("assert"), } }, plugins: [ new webpack.ProvidePlugin({ Buffer: ["buffer", "Buffer"], process: "process/browser", }), ], }

But I'm getting the following errors, I'm not sure what else is needed to make react-pdf work with the latest version of weback. Please can you advise?

PS C:\dev\workspaces\react-scratchpad\pdf> npm start

[email protected] start C:\dev\workspaces\react-scratchpad\pdf craco start

(node:21212) UnhandledPromiseRejectionWarning: Error: craco: Malformed plugin at index: 0 of 'plugins'. at C:\dev\workspaces\react-scratchpad\pdf\node_modules@craco\craco\lib\config.js:52:23 at Array.forEach () at ensureConfigSanity (C:\dev\workspaces\react-scratchpad\pdf\node_modules@craco\craco\lib\config.js:50:29) at processCracoConfig (C:\dev\workspaces\react-scratchpad\pdf\node_modules@craco\craco\lib\config.js:60:5) at loadCracoConfigAsync (C:\dev\workspaces\react-scratchpad\pdf\node_modules@craco\craco\lib\config.js:125:12) (Use node --trace-warnings ... to show where the warning was created) (node:21212) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1) (node:21212) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. PS C:\dev\workspaces\react-scratchpad\pdf>

rawedit avatar Dec 19 '21 23:12 rawedit

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Apr 19 '22 00:04 stale[bot]

same problem

SPavelV avatar Apr 19 '22 15:04 SPavelV

The configuration you provided is incorrectly set up. Instead of this: plugins: [ new webpack.ProvidePlugin({ Buffer: ["buffer", "Buffer"], process: "process/browser", }), ]

It should be this: plugins: [ {plugin: new webpack.ProvidePlugin({ Buffer: ["buffer", "Buffer"], process: "process/browser", }),} ]

stevenewald avatar Aug 24 '22 03:08 stevenewald