Resolve alias webpack helper

Payload plugin that injects webpack resolve aliases to stub out server-only modules in the admin bundle.

Community 7 1.9k/wk MIT v0.1.0

Installation

pnpm add payload-plugin-resolve-alias

About

This plugin solves a recurring webpack error in Payload's admin build where Node core modules like `util`, `express`, `express-session`, `passport`, and `nodemailer` fail to resolve because webpack 5 no longer polyfills them by default. It hooks into the `admin.webpack` config to add entries to `resolve.alias` that map those modules to `false`, telling webpack to emit an empty module instead of trying to bundle a server-only dependency for the browser. You register it in `payload.config.ts` as a normal Payload plugin. The `resolveAlias` function accepts multiple argument shapes: a plain object of `{ module: false }` pairs, an array of module names, or individual string names. It merges everything into one alias map and runs after any existing `admin.webpack` handler so your custom config is preserved. The package ships a `serverOnlyModules` constant listing the common offenders (`express`, `express-session`, `nodemailer`, `passport`, `util`), so the typical fix is a one-liner: `resolveAlias(serverOnlyModules, ['nodemailer'])`. Falsy arguments are skipped, which lets you pass conditional aliases guarded by environment checks. It targets Payload 1.x and works by transforming the `Config` object before it reaches the build. It does not add fields, collections, hooks, or endpoints. The one known limitation is that it cannot handle webpack alias configs defined as arrays.

Package info

Package name
payload-plugin-resolve-alias
Latest version
0.1.0
Unpacked size
7 kB
License
MIT
Weekly downloads
1.9k
Last publish
Nov 5, 2022

More from thgh

View profile