{"id":22303,"library":"rollup-preserve-directives","title":"rollup-preserve-directives","description":"Rollup plugin to preserve shebang and string directives (e.g., 'use strict') in bundled output. Current stable version 1.1.3, maintained actively. No external dependencies, ships TypeScript types. Key differentiator: handles shebang and directives that Rollup's tree-shaking may remove, and exposes metadata for inter-plugin communication. Renamed from rollup-swc-preserve-directives in v1.0.0.","status":"active","version":"1.1.3","language":"javascript","source_language":"en","source_url":"https://github.com/huozhi/rollup-preserve-directives","tags":["javascript","rollup","plugin","preserve","directives","typescript"],"install":[{"cmd":"npm install rollup-preserve-directives","lang":"bash","label":"npm"},{"cmd":"yarn add rollup-preserve-directives","lang":"bash","label":"yarn"},{"cmd":"pnpm add rollup-preserve-directives","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"ESM-only package; CJS require is not supported.","wrong":"const preserveDirectives = require('rollup-preserve-directives')","symbol":"default","correct":"import preserveDirectives from 'rollup-preserve-directives'"},{"note":"Type import for TypeScript users only.","wrong":"","symbol":"type PreserveDirectivesOptions","correct":"import type { PreserveDirectivesOptions } from 'rollup-preserve-directives'"},{"note":"Type for the metadata exposed via moduleParsed hook.","wrong":"","symbol":"type PluginMeta","correct":"import type { PluginMeta } from 'rollup-preserve-directives'"}],"quickstart":{"code":"import preserveDirectives from 'rollup-preserve-directives';\n\nexport default {\n  input: './src/index.js',\n  output: {\n    file: './dist/index.js',\n    format: 'cjs',\n  },\n  plugins: [\n    preserveDirectives(),\n  ],\n};","lang":"typescript","description":"Basic rollup.config.js configuration showing how to use the plugin to preserve shebang and directives."},"warnings":[{"fix":"Uninstall old package: npm uninstall rollup-swc-preserve-directives. Install new: npm install rollup-preserve-directives. Update import.","message":"Package renamed from rollup-swc-preserve-directives to rollup-preserve-directives in v1.0.0. Old package deprecated.","severity":"breaking","affected_versions":"<1.0.0"},{"fix":"No change needed unless you relied on swc-specific behavior. Remove any swc options from plugin call.","message":"v1.0.0 dropped dependency on swc/core. Plugin now uses Rollup's built-in parser only.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Upgrade to v1.0.0+ and rename package.","message":"v0.x versions (under old name rollup-swc-preserve-directives) are deprecated and receive no updates.","severity":"deprecated","affected_versions":"<1.0.0"},{"fix":"Ensure your config file uses ES module syntax (export default) and has .mjs extension or package.json type: module.","message":"Plugin only works with Rollup's ESM configuration files (rollup.config.mjs or type: module).","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use this.getModuleInfo or moduleParsed hook to check directives metadata.","message":"May not preserve directives in all cases; if you rely on specific directives being kept, verify output.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Use import syntax or rename config file to .mjs.","cause":"Using require() to import an ES module package.","error":"SyntaxError: Unexpected token 'export'"},{"fix":"Run npm install rollup-preserve-directives.","cause":"Package not installed or mismatched version.","error":"Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'rollup-preserve-directives'"},{"fix":"Use import preserveDirectives from 'rollup-preserve-directives' (default import).","cause":"Default import error, possibly using named import instead of default.","error":"TypeError: preserveDirectives is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}