> ## Documentation Index
> Fetch the complete documentation index at: https://docs.layerswap.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Build troubleshooting

> Fix Vite and Next.js build issues in the self-bundled Widget.

<Warning>
  These fixes apply only to the self-bundled `@layerswap/widget`. The recommended React and JavaScript loaders do not put these dependencies in your bundle.
</Warning>

## Vite: `process is not defined`

Install the Node polyfill plugin:

```bash theme={null}
npm install --save-dev vite-plugin-node-polyfills @vitejs/plugin-react
```

```ts title="vite.config.ts" theme={null}
import react from '@vitejs/plugin-react';
import { defineConfig } from 'vite';
import { nodePolyfills } from 'vite-plugin-node-polyfills';

export default defineConfig({
  plugins: [react(), nodePolyfills()],
  esbuild: { target: 'esnext' },
});
```

## Next.js: Node-only module errors

For webpack builds, disable browser resolution for Node-only modules and externalize optional server packages:

```ts title="next.config.ts" theme={null}
import type { NextConfig } from 'next';

const nextConfig: NextConfig = {
  webpack: (config) => {
    config.resolve.fallback = { fs: false, net: false, tls: false };
    config.externals.push('pino-pretty', 'lokijs', 'encoding');
    return config;
  },
};

export default nextConfig;
```

## Next.js: ESM package resolution

The published next builds contain extensionless ESM imports. Without transpilation, Node's SSR loader can reject an internal import with `ERR_MODULE_NOT_FOUND`, commonly for a path ending in `/knownIds`.

Add the Widget's shared packages and every installed `@layerswap/wallet-*` package to `transpilePackages`:

```ts title="next.config.ts" theme={null}
const nextConfig = {
  transpilePackages: [
    '@layerswap/widget',
    '@layerswap/widget-types',
    '@layerswap/utils',
    '@layerswap/ui-kit',
    '@layerswap/wallet-core',
    '@layerswap/wallet-evm',
    '@layerswap/wallet-starknet',
    '@layerswap/wallet-imtbl-passport',
  ],
};

export default nextConfig;
```

Replace the wallet-package entries with every chain package your host installs; include `@layerswap/wallets` too if you use the lazy descriptor package. The package names use the published `wallet-imtbl-*` and `wallet-module-*` forms. Re-check the module packages against the 2.0.0 release.
