esbuild-plugin-json-cleaner
raw JSON → 0.1.3 verified Fri May 01 auth: no javascript
An esbuild plugin for cleaning JSON files during the build process. It supports removing top-level tags (like schema references), minifying output, and customizing indentation. Current version is 0.1.3, released as an early-stage tool with peer dependency on esbuild ^0.27.2. It differentiates by being a minimal, focused plugin for JSON cleanup in esbuild builds, with TypeScript support and dual ESM/CJS exports. Suitable for workflows that need to strip metadata from JSON files before bundling.
Common errors
error TypeError: JSONCleanerPlugin is not a function ↓
cause Using CommonJS require and calling it as a function, but default export requires import or .default
fix
Use import JSONCleanerPlugin from 'esbuild-plugin-json-cleaner' or const JSONCleanerPlugin = require('esbuild-plugin-json-cleaner').default
error Error: Build failed with 1 error: error: [plugin: JSONCleaner] Cannot find module 'esbuild' ↓
cause esbuild is not installed as a dev dependency
fix
Run npm install esbuild --save-dev
error error: [plugin: JSONCleaner] Failed to read file: src/data.json ↓
cause Source file path is incorrect or file does not exist
fix
Check that src path is relative to the project root and file exists
Warnings
gotcha Default export only; CommonJS require returns undefined. ↓
fix Use import syntax or use the default export via require('esbuild-plugin-json-cleaner').default.
breaking Peer dependency esbuild ^0.27.2 required; older versions incompatible. ↓
fix Update esbuild to version ^0.27.2 or later.
gotcha Node.js >=24 required; fails on older versions. ↓
fix Use Node.js version 24 or higher.
gotcha Plugin processes only the specified src file; no glob or directory support. ↓
fix Use multiple plugin instances for multiple files or manually iterate.
gotcha removeTags removes top-level keys only; nested keys are unaffected. ↓
fix Specify full top-level keys to remove.
Install
npm install esbuild-plugin-json-cleaner yarn add esbuild-plugin-json-cleaner pnpm add esbuild-plugin-json-cleaner Imports
- default wrong
const JSONCleanerPlugin = require('esbuild-plugin-json-cleaner')correctimport JSONCleanerPlugin from 'esbuild-plugin-json-cleaner'
Quickstart
import esbuild from 'esbuild';
import JSONCleanerPlugin from 'esbuild-plugin-json-cleaner';
await esbuild.build({
outdir: 'dist',
plugins: [
JSONCleanerPlugin({
src: 'src/data.json',
out: 'data.json',
removeSchema: true,
removeTags: ['project', 'revision'],
minify: false,
space: 2,
}),
],
});