pdfreader icon indicating copy to clipboard operation
pdfreader copied to clipboard

Module Not Found: "process/browser" Error in React Integration with @fileforge/pdfreader

Open ANYURU opened this issue 1 year ago • 1 comments

I am experiencing an issue while integrating @fileforge/pdfreader into my React project. After following the documentation and installing the package, I encountered a Webpack compilation error related to the missing process/browser module.

Error Details: The following error occurs during the build process: Screenshot 2024-10-18 at 12 50 19

Additionally, I tried adding a polyfill for process in my Webpack configuration, but the error persists. The issue seems to be related to how the module is handled within @fileforge/pdfreader.

Steps to Reproduce:

  1. Install @fileforge/pdfreader in a React project.
  2. Attempt to import and use the component in the project.
  3. Run the build using Webpack (or a React build tool like Create React App).

Expected Behavior: The package should work without requiring a manual polyfill for Node.js modules like process.

Actual Behavior: The build fails with the error above.

Environment:

  • OS: macOS
  • Node.js version: v20.18.0 | v22.7.0
  • Webpack version: 5.64.4
  • React version: 18.3.1
  • @fileforge/pdfreader version: 0.1.43

Attempts to Resolve: I attempted to resolve the issue by:

  • Installing the process polyfill.
  • Modifying the Webpack configuration to include process/browser.
  • Ensuring that the paths are correctly set in the module resolution.

Despite these attempts, the error persists, suggesting a deeper issue with how @fileforge/pdfreader handles dependencies.

Request: Could you provide guidance on how to resolve this error, or update the package to avoid requiring manual Node.js polyfills when used in a browser environment like React? If possible, an example of proper integration would also be very helpful.

Thank you for your time and assistance.

ANYURU avatar Oct 18 '24 10:10 ANYURU

Hey @ANYURU, thanks for the detailed walkthrough!

Vite should handle bundling this gracefully, not sure why there are issues with Webpack specifically. It is likely being introduced by pdfjs-dist, but I can't really confirm at the moment.

Contributions regarding this are welcome!

Titou325 avatar Oct 18 '24 10:10 Titou325