Next.js Adapter
API reference for the Next.js adapter (webpack + Turbopack).
Next.js Adapter
polyq/next — Supports both webpack and Turbopack bundlers.
withPolyq(nextConfig, options?)
Wraps your Next.js config with blockchain polyfills for both bundlers.
import { withPolyq } from 'polyq/next'
const nextConfig = {
// your existing config
}
export default withPolyq(nextConfig) Parameters:
| Param | Type | Description |
|---|---|---|
nextConfig | NextConfig | Your existing Next.js configuration |
options | PolyqNextOptions | Optional polyfill and sync settings |
Returns: NextConfig
What It Does
Turbopack (Next.js 15+):
- Adds
turbopack.resolveAliasentries forfs,net,tls(browser stubs) - Adds
bufferalias tobuffer/npm package - Preserves existing
resolveAliasentries — won’t overwrite your custom aliases
Webpack (fallback):
- Adds
resolve.fallbackforbuffer(and optionallycrypto,stream) - Injects
ProvidePluginforBufferglobal - Only applies to client-side builds (skips server and edge runtime gets polyfills too)
With Options
export default withPolyq(nextConfig, {
polyfills: {
mode: 'manual',
buffer: true,
crypto: true,
},
}) Preserving Existing Config
withPolyq spreads your config and chains the webpack function:
// Your existing webpack customization is preserved
const nextConfig = {
turbopack: {
root: path.join(__dirname, '..'),
resolveAlias: {
// Your custom aliases are kept
'@/lib': './src/lib',
},
},
webpack(config, context) {
// Your custom webpack config still runs
config.externals.push('some-package')
return config
},
}
export default withPolyq(nextConfig) // Both turbopack + webpack preserved