This document provides solutions for common Webpack errors encountered during the development process. Follow the steps below to resolve each issue.
Error message: Module not found: Error: Can't resolve 'tfhe_bg.wasm'
Cause: In the codebase, there is a new URL('tfhe_bg.wasm')
which triggers a resolve by Webpack.
Possible sultions: You can add a fallback for this file by adding a resolve configuration in your webpack.config.js
:
Error message: ReferenceError: Buffer is not defined
Cause: This error occurs when the Node.js Buffer
object is used in a browser environment where it is not natively available.
Possible sultions: To resolve this issue, you need to provide browser-compatible fallbacks for Node.js core modules. Install the necessary browserified npm packages and configure Webpack to use these fallbacks.
Error message: Issues with importing ESM version
Cause: With a bundler such as Webpack or Rollup, imports will be replaced with the version mentioned in the "browser"
field of the package.json
. This can cause issues with typing.
Possible solutions:
If you encounter issues with typing, you can use this tsconfig.json using TypeScript 5.
If you encounter any other issue, you can force import of the browser package.
Error message: Issues with bundling the library, especially with SSR frameworks.
Cause: The library may not bundle correctly with certain frameworks, leading to errors during the build or runtime process.
Possible solutions: Use the prebundled version available with fhevmjs/bundle
. Embed the library with a <script>
tag and initialize it as shown below: