{"id":20659,"library":"vite-plugin-babel-macros","title":"vite-plugin-babel-macros","description":"Vite plugin that enables babel-plugin-macros support for using compile-time macros like twin.macro, styled-components/macro, or custom macros in Vite projects. Current stable version is 1.0.6, released infrequently as needed. Key differentiator: it bridges Vite's native ESM handling with babel macros, which Vite doesn't support out of the box. Note: v1.0.6 fixed ESM imports but broke Node <16; the author acknowledged it should have been a major release. Requires Vite >=2 and Node >=16.","status":"active","version":"1.0.6","language":"javascript","source_language":"en","source_url":"https://github.com/itsMapleLeaf/vite-plugin-babel-macros","tags":["javascript","typescript"],"install":[{"cmd":"npm install vite-plugin-babel-macros","lang":"bash","label":"npm"},{"cmd":"yarn add vite-plugin-babel-macros","lang":"bash","label":"yarn"},{"cmd":"pnpm add vite-plugin-babel-macros","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency: plugin requires Vite >=2 to function as a Vite plugin.","package":"vite","optional":true}],"imports":[{"note":"ESM-only package. CommonJS require will fail in Node >=16 with type:module.","wrong":"const macrosPlugin = require('vite-plugin-babel-macros')","symbol":"default","correct":"import macrosPlugin from 'vite-plugin-babel-macros'"},{"note":"The plugin is exported as default, not a named export.","wrong":"import { macrosPlugin } from 'vite-plugin-babel-macros'","symbol":"macrosPlugin","correct":"import macrosPlugin from 'vite-plugin-babel-macros'"},{"note":"Plugin types are re-exported from Vite, not from this package.","wrong":"import { Plugin } from 'vite-plugin-babel-macros'","symbol":"Plugin (type)","correct":"import type { Plugin } from 'vite'"}],"quickstart":{"code":"// vite.config.ts\nimport { defineConfig } from 'vite'\nimport macrosPlugin from 'vite-plugin-babel-macros'\n\nexport default defineConfig({\n  plugins: [macrosPlugin()],\n})\n\n// Then in your source files, use any babel macro:\n// import { css } from 'styled-components/macro'\n// const x = css`color: red;`","lang":"typescript","description":"Shows how to integrate vite-plugin-babel-macros into a Vite config, enabling babel macros like styled-components/macro."},"warnings":[{"fix":"Use import syntax and ensure Node >=16, or pin to v1.0.5 if you need CJS.","message":"v1.0.6 requires Node >=16 and ESM imports. Using CommonJS require() will throw ERR_REQUIRE_ESM.","severity":"breaking","affected_versions":">=1.0.6"},{"fix":"Upgrade to Node >=16, or stay on v1.0.5 if you must use older Node.","message":"v1.0.6 broke Node 15 and below. The author noted it should have been a major release.","severity":"breaking","affected_versions":">=1.0.6"},{"fix":"Use import macrosPlugin from 'vite-plugin-babel-macros'","message":"The plugin is exported as default, not named. Using import { macrosPlugin } will result in undefined.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"None","message":"No known deprecation warnings, but the plugin is minimally maintained.","severity":"deprecated","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Switch to import syntax and set type:module or use .mjs extension.","cause":"Using require() on an ESM-only package (v1.0.6+).","error":"ERR_REQUIRE_ESM: require() of ES Module not supported"},{"fix":"Use import macrosPlugin from 'vite-plugin-babel-macros' (no curly braces).","cause":"Trying to import { macrosPlugin } instead of default import.","error":"Error: The plugin 'vite-plugin-babel-macros' doesn't provide a named export 'macrosPlugin'"},{"fix":"Install babel-plugin-macros: npm install --dev babel-plugin-macros","cause":"Missing dependency 'babel-plugin-macros'.","error":"Module not found: Can't resolve 'babel-plugin-macros'"},{"fix":"Reinstall the package: npm install vite-plugin-babel-macros","cause":"The package is not built or not installed correctly.","error":"[vite] Internal server error: Cannot find module '/node_modules/vite-plugin-babel-macros/dist/index.js'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}