{"id":25386,"library":"esbuild-plugin-preserve-directives","title":"esbuild-plugin-preserve-directives","description":"An esbuild plugin that ensures directives like 'use client' and 'use strict' are preserved at the top of output files. Current stable version is 0.0.11. The plugin scans source files for specified directives before bundling and reinserts them into the corresponding output chunks. It supports regex-based include/exclude patterns and works with esbuild's metafile option for improved accuracy. Updated frequently with community contributions, it is primarily used with React Server Components and Node.js ESM/CJS builds. Key differentiator: it handles directives that esbuild would otherwise strip, with minimal overhead.","status":"active","version":"0.0.11","language":"javascript","source_language":"en","source_url":"https://github.com/seojunhwan/esbuild-plugin-preserve-directives","tags":["javascript","esbuild","plugin","preserve","directives","typescript"],"install":[{"cmd":"npm install esbuild-plugin-preserve-directives","lang":"bash","label":"npm"},{"cmd":"yarn add esbuild-plugin-preserve-directives","lang":"bash","label":"yarn"},{"cmd":"pnpm add esbuild-plugin-preserve-directives","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency: requires esbuild ^0.21.0 to function as a plugin","package":"esbuild","optional":false}],"imports":[{"note":"This package only exports a named export, not a default export.","wrong":"import preserveDirectivesPlugin from 'esbuild-plugin-preserve-directives'","symbol":"preserveDirectivesPlugin","correct":"import { preserveDirectivesPlugin } from 'esbuild-plugin-preserve-directives'"},{"note":"Options type is exported as a type-only export; use 'import type' for type-checking.","wrong":"import { PreserveDirectivesPluginOptions } from 'esbuild-plugin-preserve-directives'","symbol":"PreserveDirectivesPluginOptions","correct":"import type { PreserveDirectivesPluginOptions } from 'esbuild-plugin-preserve-directives'"},{"note":"CommonJS require must destructure the named export.","wrong":"const preserveDirectivesPlugin = require('esbuild-plugin-preserve-directives')","symbol":"plugin via require()","correct":"const { preserveDirectivesPlugin } = require('esbuild-plugin-preserve-directives')"}],"quickstart":{"code":"import { build } from 'esbuild';\nimport { preserveDirectivesPlugin } from 'esbuild-plugin-preserve-directives';\n\nawait build({\n  entryPoints: ['src/index.js'],\n  bundle: true,\n  outdir: 'dist',\n  metafile: true,\n  plugins: [\n    preserveDirectivesPlugin({\n      directives: ['use client', 'use strict'],\n      include: /\\.(js|ts|jsx|tsx)$/,\n      exclude: /node_modules/,\n    }),\n  ],\n});","lang":"typescript","description":"Shows how to use the plugin with esbuild, including metafile option for accuracy."},"warnings":[{"fix":"Add metafile: true to esbuild options.","message":"metafile option is not required but strongly recommended for accuracy; without it, directive preservation may be incomplete.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Upgrade esbuild to ^0.21.0 or later.","message":"Plugin requires esbuild ^0.21.0; older esbuild versions are incompatible.","severity":"breaking","affected_versions":"<0.21.0"},{"fix":"Use Node.js >=18.0.0.","message":"Node.js <18.0.0 is not supported.","severity":"deprecated","affected_versions":"<18.0.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Run 'npm install esbuild@^0.21.0' or update esbuild to compatible version.","cause":"Peer dependency version mismatch","error":"Error: The plugin 'esbuild-plugin-preserve-directives' must be used with esbuild ^0.21.0"},{"fix":"Run 'npm install -D esbuild-plugin-preserve-directives'.","cause":"Package not installed","error":"Cannot find module 'esbuild-plugin-preserve-directives'"},{"fix":"Use 'import { preserveDirectivesPlugin } from 'esbuild-plugin-preserve-directives''.","cause":"Default import used instead of named import","error":"Uncaught TypeError: preserveDirectivesPlugin is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}