{"id":26949,"library":"esbuild-preserve-whitespace","title":"esbuild-preserve-whitespace","description":"An esbuild plugin that preserves blank lines and whitespace during TypeScript transpilation. Version 1.1.1 requires esbuild ^0.19.0 and the legalComments: 'inline' option. It works by replacing blank lines with marker comments before esbuild processes files, then removing them after. Unlike esbuild's default behavior (which strips most whitespace), this plugin provides configurable preservation of formatting, useful for debugging, code review, or when output readability matters. The plugin is lightweight, typed (TypeScript), and maintained on GitHub. It has no runtime dependencies beyond esbuild.","status":"active","version":"1.1.1","language":"javascript","source_language":"en","source_url":"https://github.com/dagimg-dot/esbuild-preserve-whitespace","tags":["javascript","esbuild","plugin","typescript","whitespace","preserve"],"install":[{"cmd":"npm install esbuild-preserve-whitespace","lang":"bash","label":"npm"},{"cmd":"yarn add esbuild-preserve-whitespace","lang":"bash","label":"yarn"},{"cmd":"pnpm add esbuild-preserve-whitespace","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency; esbuild >=0.19.0 required for plugin compatibility","package":"esbuild","optional":false}],"imports":[{"note":"Package is ESM-only; CommonJS require() will fail. Use dynamic import() if needed in CJS.","wrong":"const esbuildPreserveWhitespacePlugin = require('esbuild-preserve-whitespace')","symbol":"esbuildPreserveWhitespacePlugin","correct":"import { esbuildPreserveWhitespacePlugin } from 'esbuild-preserve-whitespace'"},{"note":"PluginOptions is a type export; use 'import type' to avoid runtime issues. Available as named type export.","wrong":"import { PluginOptions } from 'esbuild-preserve-whitespace'","symbol":"PluginOptions","correct":"import type { PluginOptions } from 'esbuild-preserve-whitespace'"},{"note":"Default export is not provided; only named export exists. Attempting default import will result in undefined.","wrong":"","symbol":"default import","correct":"import esbuildPreserveWhitespacePlugin from 'esbuild-preserve-whitespace'"}],"quickstart":{"code":"import { esbuildPreserveWhitespacePlugin } from 'esbuild-preserve-whitespace';\nimport * as esbuild from 'esbuild';\n\nawait esbuild.build({\n  entryPoints: ['src/index.ts'],\n  outfile: 'dist/index.js',\n  bundle: true,\n  legalComments: 'inline', // Required\n  plugins: [\n    esbuildPreserveWhitespacePlugin({\n      verbose: false,\n    }),\n  ],\n});","lang":"typescript","description":"Basic esbuild build with whitespace preservation plugin. Note that legalComments: 'inline' is mandatory."},"warnings":[{"fix":"Add 'legalComments: \"inline\"' to esbuild options. Without it, marker comments used to preserve whitespace are removed.","message":"legalComments must be set to 'inline' or plugin will silently fail","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Ensure build process handles errors (e.g., try/catch) and consider using a clean working directory. The plugin restores files on success but not on failure.","message":"Plugin modifies source files temporarily; if the build crashes, source files may remain altered","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"No fix; this is by design. Plugin operates on esbuild's onLoad callback; other files are untouched.","message":"Only works with files processed by esbuild; does not affect non-esbuild outputs or external files","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Upgrade to v1.1.0 or later which includes improved error recovery.","message":"v1.0.0 had incomplete error handling","severity":"deprecated","affected_versions":"==1.0.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Add 'legalComments: \"inline\"' to your esbuild configuration object.","cause":"legalComments not set or set to a value other than 'inline' in esbuild options.","error":"Error: The plugin 'esbuild-preserve-whitespace' requires 'legalComments' to be set to 'inline'."},{"fix":"Use 'import { esbuildPreserveWhitespacePlugin } from 'esbuild-preserve-whitespace'' or 'const { esbuildPreserveWhitespacePlugin } = await import('esbuild-preserve-whitespace')'.","cause":"Incorrect import: using require() in CJS context or importing default instead of named export.","error":"TypeError: esbuildPreserveWhitespacePlugin is not a function"},{"fix":"Run 'npm install -D esbuild-preserve-whitespace' or equivalent for your package manager.","cause":"Package not installed or not in node_modules.","error":"Error: Cannot find module 'esbuild-preserve-whitespace'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}