{"id":22178,"library":"rollup-plugin-preserve-directives","title":"rollup-plugin-preserve-directives","description":"A Rollup plugin that preserves file-level directives (e.g., 'use client', 'use server') when using preserveModules: true. Version 0.4.0 is the current stable release, with a simple API and minimal configuration. Unlike bundling, where directives are meaningless per file, this plugin ensures each preserved module retains its directives, enabling patterns like React Server Components without separate entrypoints. Still considered early-stage (largely untested) but functional. Filters via include/exclude globs. Warning suppression options exist. Supports Rollup 2–4. Ships TypeScript types.","status":"active","version":"0.4.0","language":"javascript","source_language":"en","source_url":"https://github.com/Ephem/rollup-plugin-preserve-directives","tags":["javascript","rollup-plugin","typescript"],"install":[{"cmd":"npm install rollup-plugin-preserve-directives","lang":"bash","label":"npm"},{"cmd":"yarn add rollup-plugin-preserve-directives","lang":"bash","label":"yarn"},{"cmd":"pnpm add rollup-plugin-preserve-directives","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency – plugin works with Rollup 2.x, 3.x, or 4.x","package":"rollup","optional":true}],"imports":[{"note":"Default export, not named.","wrong":"import { preserveDirectives } from 'rollup-plugin-preserve-directives'","symbol":"preserveDirectives","correct":"import preserveDirectives from 'rollup-plugin-preserve-directives'"},{"note":"CJS require of default export.","wrong":"const { preserveDirectives } = require('rollup-plugin-preserve-directives')","symbol":"preserveDirectives","correct":"const preserveDirectives = require('rollup-plugin-preserve-directives')"},{"note":"TypeScript users can import the Options type for plugin configuration.","wrong":"","symbol":"type Options","correct":"import type { Options } from 'rollup-plugin-preserve-directives'"}],"quickstart":{"code":"// rollup.config.js\nimport preserveDirectives from 'rollup-plugin-preserve-directives';\n\nexport default {\n  input: 'src/index.js',\n  output: {\n    dir: 'dist',\n    format: 'esm',\n    preserveModules: true,\n  },\n  plugins: [\n    preserveDirectives({\n      exclude: ['**/*.css'],\n    }),\n  ],\n};\n","lang":"javascript","description":"Configure Rollup with preserveModules: true and add the plugin to retain 'use client' directives in output modules."},"warnings":[{"fix":"Set output.preserveModules: true in your Rollup config.","message":"preserveModules must be true for the plugin to work; otherwise it warns and does nothing.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Set terser compress.directives: false to preserve directives.","message":"Minifiers like terser may remove directives; terser's compress.directives defaults to true.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Avoid using suppressPreserveModulesWarning; use onwarn in Rollup to handle warnings.","message":"suppressPreserveModulesWarning option exists but will be removed in future versions.","severity":"deprecated","affected_versions":">=0.4.0"},{"fix":"Add an onwarn handler to ignore directive warnings, e.g., onwarn: (warning, defaultHandler) => { if (!warning.message.includes('use client')) defaultHandler(warning); }","message":"Rollup still emits warnings about module-level directives; the plugin does not suppress them.","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Set output.preserveModules: true and add preserveDirectives() to the plugins array.","cause":"preserveModules is not enabled, or the plugin is not used.","error":"Module level directives cause errors when bundled, 'use client' was ignored."},{"fix":"Set output.preserveModules: true in your Rollup config.","cause":"The plugin is used but preserveModules is not set to true.","error":"preserveModules must be true for preserveDirectives to work."},{"fix":"Configure minifier to preserve directives, e.g., terser({ compress: { directives: false } }).","cause":"Terser or other minifier removes directives by default.","error":"Directive 'use client' was removed after minification."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}