rollup-plugin-resolve-alias
raw JSON → 0.2.1 verified Mon Apr 27 auth: no javascript deprecated
A Rollup plugin to create module import aliases, simplifying paths in bundled code. Current stable version is 0.2.1, with no active development since 2018. It provides a simple API via an 'aliases' object, but lacks features like array aliases or custom resolvers found in more modern alternatives like @rollup/plugin-alias. Ships TypeScript types. Requires Rollup >=0.20.0. Use with caution for new projects; prefer @rollup/plugin-alias instead.
Common errors
error Error: Cannot find module 'rollup-plugin-resolve-alias' ↓
cause Package not installed or installed incorrectly.
fix
Run 'npm install rollup-plugin-resolve-alias --save-dev' or ensure it's in devDependencies.
error TypeError: resolveAlias is not a function ↓
cause CommonJS require used instead of ESM import.
fix
Use ES module syntax: import resolveAlias from 'rollup-plugin-resolve-alias'
error Uncaught TypeError: Cannot destructure property 'aliases' of 'undefined' or 'null'. ↓
cause Calling resolveAlias() without passing an options object.
fix
Pass an object with an 'aliases' key: resolveAlias({ aliases: { '@': './src' } })
Warnings
deprecated Package is no longer maintained. Consider using @rollup/plugin-alias instead. ↓
fix Replace with @rollup/plugin-alias: npm install @rollup/plugin-alias -D and update config.
breaking Version 0.2.0 changed the API from an options object with 'resolve' to the current 'aliases' object. ↓
fix If migrating from 0.1.x, change the plugin configuration to use the 'aliases' key instead of top-level mappings.
gotcha Alias values must be absolute paths or relative to the project root, not relative to the importing file. ↓
fix Ensure aliases resolve correctly by using absolute paths or paths relative to process.cwd().
Install
npm install rollup-plugin-resolve-alias yarn add rollup-plugin-resolve-alias pnpm add rollup-plugin-resolve-alias Imports
- default wrong
const resolveAlias = require('rollup-plugin-resolve-alias')correctimport resolveAlias from 'rollup-plugin-resolve-alias' - resolveAlias wrong
import { resolveAlias } from 'rollup-plugin-resolve-alias'correctimport resolveAlias from 'rollup-plugin-resolve-alias' - types
import type { RollupPluginResolveAliasOptions } from 'rollup-plugin-resolve-alias'
Quickstart
import resolveAlias from 'rollup-plugin-resolve-alias';
export default {
input: 'src/main.js',
output: { file: 'bundle.js', format: 'cjs' },
plugins: [
resolveAlias({
aliases: {
'@': './src',
'utils': './src/utils'
}
})
]
};