rollup-plugin-extensions

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

A Rollup plugin that resolves local files with custom extensions (e.g., .tsx, .ts, .jsx). Version 0.1.0 is the only release; it is in early development with no test suite. Unlike rollup-plugin-node-resolve, it avoids resolving node_modules entirely, focusing solely on adding extension support for local imports. It is primarily intended for building packages where you control the dependency graph, and it automatically resolves index files based on the provided extensions.

error TypeError: extensions is not a function
cause Imported the plugin as a named export instead of default.
fix
Change import to import extensions from 'rollup-plugin-extensions'.
error Error: Could not resolve './foo' from src/index.ts
cause Extension not included in the plugin's extensions list.
fix
Add the missing extension (e.g., '.ts') to the extensions array in the plugin configuration.
error Module not found: Error: Can't resolve './bar' in '/path/to/project'
cause The plugin is not installed or not applied in rollup config.
fix
Install the plugin (yarn add -D rollup-plugin-extensions) and add it to the plugins array.
gotcha Default extensions are ['.mjs', '.js']; if you need TypeScript, you must specify extensions explicitly.
fix Provide an extensions array with desired extensions.
gotcha This plugin does NOT resolve node_modules; it only resolves local imports. Using it together with rollup-plugin-node-resolve may cause unexpected behavior.
fix Avoid combining with rollup-plugin-node-resolve unless you understand the conflict.
gotcha No test suite exists; the plugin may have undiscovered bugs.
fix Use with caution and test your build thoroughly.
gotcha The plugin only handles relative imports (starting with './' or '../'). Absolute imports are not transformed.
fix Use another plugin like rollup-plugin-alias for absolute imports.
npm install rollup-plugin-extensions
yarn add rollup-plugin-extensions
pnpm add rollup-plugin-extensions

Shows a basic Rollup configuration using rollup-plugin-extensions to resolve TypeScript and JSX files locally.

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

export default {
  input: 'src/index.ts',
  output: {
    file: 'dist/bundle.js',
    format: 'cjs',
  },
  plugins: [
    extensions({
      extensions: ['.ts', '.tsx', '.js', '.jsx'],
      resolveIndex: true,
    }),
  ],
};
// Now you can import './foo.ts' without specifying the extension in the source code.