{"id":16519,"library":"rehype-remove-meta-http-equiv","title":"Rehype Plugin to Remove HTTP-Equiv Meta Elements","description":"`rehype-remove-meta-http-equiv` is a rehype plugin designed to optimize HTML output by removing `<meta>` elements that possess the `http-equiv` attribute. Specifically, it targets `content-type` and `content-language` meta tags, which can often be set more efficiently through other means (e.g., `charset` attribute on `<meta>` or `lang` attribute on `<html>`). This package is part of the broader unified ecosystem, focusing on transforming HTML syntax trees (hast). Currently at version 4.0.1, this package, along with other rehype plugins, aligns with the modern JavaScript module system, being ESM-only and requiring Node.js 16 or newer for its operation. Its primary purpose is to help reduce the transfer size of HTML documents, contributing to faster page loads without altering the semantic meaning of the document when alternatives for setting charset or language are present.","status":"active","version":"4.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/rehypejs/rehype-minify#main","tags":["javascript","html","http-equiv","mangle","meta","minify","plugin","rehype","rehype-plugin","typescript"],"install":[{"cmd":"npm install rehype-remove-meta-http-equiv","lang":"bash","label":"npm"},{"cmd":"yarn add rehype-remove-meta-http-equiv","lang":"bash","label":"yarn"},{"cmd":"pnpm add rehype-remove-meta-http-equiv","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core ecosystem dependency for rehype plugins; processes the syntax tree.","package":"unified","optional":false}],"imports":[{"note":"This package is ESM-only since v4. CommonJS 'require' is not supported.","wrong":"const rehypeRemoveMetaHttpEquiv = require('rehype-remove-meta-http-equiv')","symbol":"rehypeRemoveMetaHttpEquiv","correct":"import rehypeRemoveMetaHttpEquiv from 'rehype-remove-meta-http-equiv'"},{"note":"When used in rehype CLI configuration (e.g., package.json or .rehyperc), refer to the plugin by its string name without explicit import.","symbol":"rehypeRemoveMetaHttpEquiv (CLI config)","correct":"\"plugins\": [\"rehype-remove-meta-http-equiv\"]"},{"note":"While `rehypeRemoveMetaHttpEquiv` is a function, its usage within the `unified` ecosystem often involves `VFile` for input/output and processing messages. The plugin itself is typed, so TypeScript understands its function signature.","symbol":"rehypeRemoveMetaHttpEquiv (Type)","correct":"import type { VFile } from 'vfile'"}],"quickstart":{"code":"import rehypeParse from 'rehype-parse';\nimport rehypeRemoveMetaHttpEquiv from 'rehype-remove-meta-http-equiv';\nimport rehypeStringify from 'rehype-stringify';\nimport {read} from 'to-vfile';\nimport {unified} from 'unified';\nimport {join} from 'node:path';\nimport {tmpdir} from 'node:os';\nimport {writeFile} from 'node:fs/promises';\n\nasync function processHtml() {\n  const inputHtml = `<!doctype html>\n<html lang=\"en-GB\">\n  <head>\n    <meta charset=\"utf8\">\n    <meta http-equiv=\"content-type\" content=\"text/html; charset=chinese\">\n    <meta http-equiv=\"content-language\" content=\"en-US\">\n  </head>\n  <body>\n    <h1>Hello World</h1>\n    <p>This is a test document to show meta http-equiv removal.</p>\n  </body>\n</html>`;\n\n  // Create a temporary file to simulate reading from a file system\n  const tempFilePath = join(tmpdir(), 'input.html');\n  await writeFile(tempFilePath, inputHtml, 'utf8');\n\n  const file = await unified()\n    .use(rehypeParse, {fragment: false}) // Ensure full document parsing\n    .use(rehypeRemoveMetaHttpEquiv)\n    .use(rehypeStringify)\n    .process(await read(tempFilePath));\n\n  console.log('Original HTML:\\n', inputHtml);\n  console.log('\\nProcessed HTML:\\n', String(file));\n  // Expected output will have the meta http-equiv tags removed.\n}\n\nprocessHtml().catch(console.error);\n","lang":"typescript","description":"This example demonstrates how to use `rehype-remove-meta-http-equiv` within a unified processing pipeline to strip `http-equiv` meta tags from an HTML document, showing the transformation from input to optimized output."},"warnings":[{"fix":"Migrate your project to use ECMAScript Modules (ESM) syntax with 'import' statements, or ensure your environment supports ESM.","message":"This package is ESM-only since version 4. Attempting to use 'require()' will result in an 'ERR_REQUIRE_ESM' error.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Upgrade your Node.js runtime to version 16 or later.","message":"Version 4.0.0 and above require Node.js 16 or newer. Older Node.js versions are not supported, leading to potential runtime errors or unexpected behavior.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Always use `rehype-sanitize` (e.g., `.use(rehypeSanitize)`) in your processing pipeline when dealing with untrusted HTML content to prevent XSS attacks.","message":"As rehype processes HTML, untrusted input combined with improper use can lead to Cross-Site Scripting (XSS) vulnerabilities. This plugin removes meta tags but does not sanitize other HTML content.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Update your `unified`, `rehype-parse`, and `rehype-stringify` packages to their latest major versions (e.g., `unified@^13`, `rehype-parse@^9`, `rehype-stringify@^10`) to ensure compatibility.","message":"The `rehype` ecosystem, including this plugin's compatibility, relies on `unified` v13+ and `hast` v3+. Incompatible versions can cause type errors or runtime failures.","severity":"breaking","affected_versions":">=4.0.0"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"Change your import statement from `const plugin = require('rehype-remove-meta-http-equiv')` to `import plugin from 'rehype-remove-meta-http-equiv'` and ensure your project is configured for ESM (e.g., by adding `\"type\": \"module\"` to `package.json`).","cause":"Attempting to import the ESM-only `rehype-remove-meta-http-equiv` package using CommonJS `require()` syntax.","error":"ERR_REQUIRE_ESM: require() of ES Module ... not supported. Instead change the require of index.js in ... to a dynamic import() call."},{"fix":"Ensure `unified` is imported using `import { unified } from 'unified'` and that you are using a compatible version (unified@^13 for rehype v4.x plugins).","cause":"The `unified` package was not imported correctly, or an incompatible version is being used (e.g., an older CommonJS `require` of a new ESM `unified`).","error":"TypeError: unified is not a function"},{"fix":"Add `\"type\": \"module\"` to your `package.json` file or use the `.mjs` file extension for your module file to explicitly enable ESM.","cause":"You are attempting to use an `import` statement for `rehype-remove-meta-http-equiv` in a file that is being treated as a CommonJS module.","error":"SyntaxError: Cannot use import statement outside a module"}],"ecosystem":"npm"}