rollup-plugin-includepaths
raw JSON → 0.2.4 verified Mon Apr 27 auth: no javascript maintenance
A Rollup plugin that allows importing modules using relative paths from configured base directories. Version 0.2.4 is the latest stable release (August 2020), with no further updates expected. It helps avoid deep relative imports by defining alias paths, similar to Webpack's resolve.alias. Unlike @rollup/plugin-alias, this plugin supports multiple path prefixes and automatic file extension resolution. Lightweight with no runtime dependencies, but unmaintained since 2020.
Common errors
error Error: Could not resolve 'someModule' from '...' ↓
cause The module name is not found in any of the configured paths or the include map.
fix
Add the module path to the 'paths' array or use 'include' option with explicit file path.
error TypeError: includePaths is not a function ↓
cause Using import incorrectly, e.g., 'import { includePaths } from 'rollup-plugin-includepaths''
fix
Use default import: 'import includePaths from 'rollup-plugin-includepaths''
error Error: Cannot find module 'rollup-plugin-includepaths' ↓
cause Plugin not installed or package missing from node_modules.
fix
Run 'npm install rollup-plugin-includepaths --save-dev'
Warnings
deprecated No updates since 2020; consider using @rollup/plugin-alias for active maintenance. ↓
fix Migrate to '@rollup/plugin-alias' with similar configuration.
gotcha If no paths option is given, the plugin resolves from the current working directory, which may cause unexpected matches. ↓
fix Always specify an explicit paths array in options.
gotcha The plugin does not handle node_modules by default; it only looks in the provided paths. ↓
fix Use @rollup/plugin-node-resolve alongside this plugin for node_modules resolution.
breaking Version 0.2.0 dropped support for Node.js <6; may break on older runtimes. ↓
fix Upgrade Node.js to >=6 or stick with 0.1.x.
Install
npm install rollup-plugin-includepaths yarn add rollup-plugin-includepaths pnpm add rollup-plugin-includepaths Imports
- includePaths wrong
const includePaths = require('rollup-plugin-includepaths');correctimport includePaths from 'rollup-plugin-includepaths'; - options
import includePaths from 'rollup-plugin-includepaths'; const options = { paths: ['src/lib'] };
Quickstart
// rollup.config.js
import includePaths from 'rollup-plugin-includepaths';
export default {
input: 'src/main.js',
output: { file: 'dist/bundle.js', format: 'cjs' },
plugins: [
includePaths({
paths: ['src/lib', 'src/other'],
external: [],
extensions: ['.js', '.json', '.html']
})
]
};
// Now in any file inside src/lib or src/other, use:
// import { Foo } from 'one/foo'; // resolves to src/lib/one/foo.js or src/other/one/foo.js