This esbuild plugin automatically adds file extensions to import/export specifiers in bundled JavaScript output, addressing the common requirement for explicit extensions when targeting Node.js ESM or other environments that enforce extension inclusion. Version 2.1.4 (npm) requires Node >=14 and npm >=7. It ships with TypeScript types and has zero runtime dependencies. Unlike manual post-processing or bundler-agnostic solutions, this integrates directly as an esbuild plugin, offering fine-grained control over which extension (.js, .mjs, .cjs) to append based on the build target. The plugin handles dynamic imports, re-exports, and preserves URL imports. It sees active maintenance with regular updates aligned to esbuild API changes.
npm install esbuild-plugin-file-path-extensionsVerified import paths — ran on the pinned version, not inferred.
Demonstrates using the plugin with esbuild to convert .ts imports to .mjs extensions for Node ESM output.
Ensure all files requiring extension rewriting are included in the build via entryPoints or resolve extensions.
Use distinct extensions like .ts -> .mjs or .ts -> .js for actual effect.
Change `import { filePathExtensions } from 'esbuild-plugin-file-path-extensions'` to `import filePathExtensions from 'esbuild-plugin-file-path-extensions'`.Use esbuild's `alias` or `external` settings for bare specifiers.
Change to: `import filePathExtensions from 'esbuild-plugin-file-path-extensions'`
Switch your project to ESM (type: module in package.json) or use dynamic import: `const filePathExtensions = (await import('esbuild-plugin-file-path-extensions')).default;`Set inFileExtension to match the file extensions in your source (e.g., '.ts') and outFileExtension to the desired output extension (e.g., '.mjs').
No dependency data recorded yet.