
Security News
Next.js Patches Critical Middleware Vulnerability (CVE-2025-29927)
Next.js has patched a critical vulnerability (CVE-2025-29927) that allowed attackers to bypass middleware-based authorization checks in self-hosted apps.
esbuild-plugin-file-path-extensions
Advanced tools
An esbuild plugin to automatically insert file extensions in your built JavaScript files based on the specified target
An esbuild plugin to automatically insert file extensions in your built JavaScript files based on the specified target
Table of Contents
In order to properly and fully support packaging your code for both CJS and ESM
when using esbuild you will want to ensure that all your imports and exports are
using their respective file extensions (i.e. .js
for CJS and .mjs
for ESM)
to ensure that NodeJS can always load the appropriate files when they are within
the same folder. However, managing this manually is an absolute nightmare and
annoyance to do in the source code. This plugin alleviates that issue by
automatically appending the file path extensions when building the code.
You can use the following command to install this package, or replace
npm install -D
with your package manager of choice.
npm install -D esbuild-plugin-file-path-extensions
Warning When using this plugin you HAVE to set the
bundle
option to true for file paths to be resolved correctly. Do note however then when doing this your code will NOT bundle all into 1 file. An example of where this plugin is used and what the output will be after it is used can be found at sapphiredev/framework
Note If you import a file and append a file one of the file extensions
js
,cjs
,mjs
,ts
,cts
, ormts
then this plugin will skip that import and use the originally provided extension. This is to ensure that no double file extensions are added.
esbuild
Add the plugin to your esbuild options, i.e.:
const esbuild = require('esbuild');
const { resolve } = require('path');
const {
esbuildPluginFilePathExtensions
} = require('esbuild-plugin-file-path-extensions');
await esbuild.build({
format: 'cjs',
entryPoints: [resolve(__dirname, './src/index.ts')],
outdir: resolve(__dirname, './dist'),
bundle: true,
plugins: [esbuildPluginFilePathExtensions()]
});
tsup
Add the plugin to your tsup.config.ts
, i.e.:
import { defineConfig } from 'tsup';
import { resolve } from 'path';
import { esbuildPluginFilePathExtensions } from 'esbuild-plugin-file-path-extensions';
await defineConfig({
format: ['cjs', 'esm'],
entry: ['src/**/*.ts'],
outDir: './dist',
bundle: true,
esbuildPlugins: [esbuildPluginFilePathExtensions()]
});
The plugin accepts the following options:
esm
: Boolean, whether the current build is for ESM or not. Defaults to
build.initialOptions?.define?.TSUP_FORMAT === '"esm"'
in order to account
for the cross-target capabilities of tsup
.
cjsExtension
: The extension to apply for CJS code. Defaults to js
. Make
sure to NOT start with a leading .
.
esmExtension
: The extension to apply for ESM code. Defaults to mjs
. Make
sure to NOT start with a leading .
.
filter
: This is an advanced use-case option with which you can filter which
files esbuild should apply this plugin on
namespace
: This is an advanced use-case option through which the
esbuild namespace can be
configured
Favware projects are and always will be open source, even if we don't get donations. That being said, we know there are amazing people who may still want to donate just to show their appreciation. Thank you very much in advance!
We accept donations through Ko-fi, Paypal, Patreon, GitHub Sponsorships, and various cryptocurrencies. You can use the buttons below to donate through your method of choice.
Donate With | Address |
---|---|
Ko-fi | Click Here |
Patreon | Click Here |
PayPal | Click Here |
GitHub Sponsors | Click Here |
Bitcoin | 1E643TNif2MTh75rugepmXuq35Tck4TnE5 |
Ethereum | 0xF653F666903cd8739030D2721bF01095896F5D6E |
LiteCoin | LZHvBkaJqKJRa8N7Dyu41Jd1PDBAofCik6 |
Please make sure to read the Contributing Guide before making a pull request.
Thank you to all the people who already contributed!
FAQs
An esbuild plugin to automatically insert file extensions in your built JavaScript files based on the specified target
The npm package esbuild-plugin-file-path-extensions receives a total of 4,231 weekly downloads. As such, esbuild-plugin-file-path-extensions popularity was classified as popular.
We found that esbuild-plugin-file-path-extensions demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Next.js has patched a critical vulnerability (CVE-2025-29927) that allowed attackers to bypass middleware-based authorization checks in self-hosted apps.
Security News
A survey of 500 cybersecurity pros reveals high pay isn't enough—lack of growth and flexibility is driving attrition and risking organizational security.
Product
Socket, the leader in open source security, is now available on Google Cloud Marketplace for simplified procurement and enhanced protection against supply chain attacks.