rollup-plugin-import-folder

raw JSON →
1.0.6 verified Mon Apr 27 auth: no javascript

A Rollup plugin that resolves imports using folder names instead of explicit file paths. It transforms import statements like `import './hello-world'` into `import './hello-world/hello-world.js'`, making modular component-based projects easier to manage by eliminating the need for index.js files. Version 1.0.6 is stable and maintained, supporting Rollup versions 1.x through 4.x. It is published on npm and aimed at developers using bundlers for JavaScript or TypeScript projects. The plugin ships with TypeScript definitions and is configured with include/exclude options. It is a lightweight utility solution for teams organizing components in folders.

error Error: Could not resolve './hello-world' from src/index.js
cause Folder does not contain a file named hello-world.js or the import path is incorrect.
fix
Create src/hello-world/hello-world.js with a default or named export, or check the folder name spelling.
error TypeError: folder is not a function
cause The plugin is imported incorrectly (e.g., using named import instead of default).
fix
Use import folder from 'rollup-plugin-import-folder' (default import).
error [!] (plugin rpt2) RollupError: Could not resolve entry module
cause Plugin version incompatible with Rollup v4; plugin uses dynamic require which is not allowed.
fix
Update rollup-plugin-import-folder to latest version (>=1.0.6) or use older Rollup (<4).
deprecated Plugin options `include` and `exclude` are deprecated since v1.0.5
fix Remove include/exclude options; they are no longer needed as the plugin always resolves folder imports.
gotcha Import path must match folder name exactly; case-sensitive on some file systems
fix Verify folder name and import path casing, especially on Linux/macOS.
gotcha Plugin does not support dynamic imports (import())
fix Use static imports for folder resolution; dynamic imports will remain unchanged.
gotcha Resolves only .js and .mjs files; other extensions like .ts or .jsx are ignored unless configured via Rollup's resolve plugin
fix Ensure that files inside folders have .js or .mjs extensions, or use @rollup/plugin-typescript or @rollup/plugin-babel for other extensions.
gotcha Plugin works only with relative imports starting with './' or '../'
fix Absolute imports or bare specifiers are not processed; use relative paths for folder resolution.
npm install rollup-plugin-import-folder
yarn add rollup-plugin-import-folder
pnpm add rollup-plugin-import-folder

Basic usage showing how to import and configure the plugin in a Rollup config, along with an example of how folder imports are resolved.

// rollup.config.js
import folder from 'rollup-plugin-import-folder';

export default {
  input: 'src/index.js',
  output: {
    file: 'dist/bundle.js',
    format: 'esm'
  },
  plugins: [folder()]
};

// src/index.js
import './hello-world'; // resolves to ./hello-world/hello-world.js

// src/hello-world/hello-world.js
export const message = 'Hello World!';