{"id":25413,"library":"esbuild-plugin-text-replace","title":"esbuild-plugin-text-replace","description":"An esbuild plugin for replacing text or regex patterns in files before bundling. Current stable version is 1.3.0. It supports file filtering via regex, namespace targeting, and the standard String.prototype.replaceAll pattern syntax (including replacer functions). Key differentiators: lightweight (no heavy dependencies), supports esbuild pipe mode for integration with other plugins, and requires Node >=10.1.0. Use it for build-time substitutions like version strings, transforming imports, or injecting constants. Not actively maintained (last release 2021).","status":"maintenance","version":"1.3.0","language":"javascript","source_language":"en","source_url":"https://github.com/aheissenberger/esbuild-plugin-text-replace","tags":["javascript","esbuild","plugin","replace","regex","text","module","typescript"],"install":[{"cmd":"npm install esbuild-plugin-text-replace","lang":"bash","label":"npm"},{"cmd":"yarn add esbuild-plugin-text-replace","lang":"bash","label":"yarn"},{"cmd":"pnpm add esbuild-plugin-text-replace","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"ESM-only; requires ESM context. Default export is a function.","wrong":"const textReplace = require('esbuild-plugin-text-replace')","symbol":"default","correct":"import textReplace from 'esbuild-plugin-text-replace'"}],"quickstart":{"code":"import esbuild from 'esbuild';\nimport textReplace from 'esbuild-plugin-text-replace';\n\nawait esbuild.build({\n  entryPoints: ['./src/index.js'],\n  outfile: 'dist/bundle.js',\n  bundle: true,\n  plugins: [\n    textReplace({\n      include: /\\.js$/,\n      pattern: [\n        ['__VERSION__', '\"1.0.0\"'],\n        [/(\\s*)const\\s+/g, '$1let ']\n      ]\n    })\n  ]\n});","lang":"javascript","description":"Shows basic usage: replacing __VERSION__ with a string and changing const to let in all .js files."},"warnings":[{"fix":"Set include to a specific regex, e.g., include: /\\.js$/.","message":"include regex default is /.*/ which matches all files, causing significant build slowdown. Always specify a narrow include filter.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Always use /g flag in regex patterns, e.g., /foo/g.","message":"Patterns without the global flag (/g) will only replace the first occurrence. This is a common mistake since the plugin uses String.replaceAll semantics internally.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Upgrade Node to >=10.1.0 or use a polyfill.","message":"The plugin requires Node >=10.1.0 due to use of fs.promises. Older Node versions will throw errors.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Set namespace: '' in the pipe plugin configuration.","message":"When used in pipe mode, the namespace option must be set to empty string '', otherwise the plugin may not work as expected.","severity":"gotcha","affected_versions":">=1.2.0"},{"fix":"Consider alternatives like @chialab/esbuild-plugin-replace or esbuild-plugin-replace for active support.","message":"The package is no longer actively maintained; last release was in 2021. Issues may remain unresolved.","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":"Upgrade Node to >=10.1.0 or use a polyfill for fs.promises.","cause":"Node version below 10.1.0 does not support fs.promises.","error":"Error: The plugin esbuild-plugin-text-replace requires Node >=10.1.0"},{"fix":"Use ESM import: import textReplace from 'esbuild-plugin-text-replace'","cause":"Using CommonJS require() in an ESM-only package, or incorrect import.","error":"TypeError: textReplace is not a function"},{"fix":"Ensure the replacer function always returns a string.","cause":"Replacer function returned a non-string value (e.g., undefined).","error":"Build failed: Replace callback must return a string"},{"fix":"Provide pattern as an array of tuples: [[/regex/g, 'replacement'], ['text', 'replacement']]","cause":"Passing pattern as an object or array of non-tuples.","error":"Error: Pattern array must contain tuples of [pattern, replacement]"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}