Next.js requires webpack fallback configuration
When using the Layerswap Widget with Next.js, you may encounter errors related to Node.js modules that aren’t available in the browser environment, such asfs, net, or tls.
Configure webpack fallbacks in next.config.ts
Add the following webpack configuration to your next.config.ts (or next.config.js) file:
What this configuration does
resolve.fallback: Tells webpack to not attempt to polyfillfs,net, andtlsmodules, which are Node.js-specific and not needed in the browser.externals: Excludespino-pretty,lokijs, andencodingfrom the bundle, as these are optional dependencies that may cause build issues.
If you’re also experiencing ESM module resolution errors, see Next.js Transpile Packages for additional configuration.