Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslnode 18–223 runs
build_error
glibcnode 18–223 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
default
✓ import macros from 'unplugin-parcel-macros'
✗ const macros = require('unplugin-parcel-macros')
ESM-only; default export is an object with .webpack(), .vite(), .rollup(), .esbuild() methods.
webpack
✓ macros.webpack()
✗ macros.webpack
Call the method to get the plugin instance. Used in both plain Webpack and Next.js.
vite
✓ macros.vite()
✗ macros.vite
Call the method to get the Vite plugin.
Shows how to add the Vite plugin and use a macro with the import attribute to generate a regex at build time.
// vite.config.js
import macros from 'unplugin-parcel-macros';
import { defineConfig } from 'vite';
export default defineConfig({
plugins: [
macros.vite()
]
});
// src/index.js
import regexgen from 'regexgen' with { type: 'macro' };
const regex = regexgen(['foo', 'bar', 'baz']);
export default regex;
Debug
Known issues
gotchaImport attributes syntax (with {type: 'macro'}) is not supported in older bundlers or Node versions without transpilation.fixEnsure your toolchain supports the syntax or use a transpiler like SWC or Babel that strips the attribute.
affects: < Node 18, bundlers without import attributes support
breakingMacros must be imported with the exact attribute with {type: 'macro'}. Using a non-standard syntax like assert {type: 'macro'} will not work.fixUse with {type: 'macro'} as per the import attributes proposal. affects: all
gotchaThe macro module is executed at build time and cannot access runtime variables from the calling module.fixEnsure macro arguments are compile-time constants or expressions evaluable at build time.
affects: all
deprecatedImport attributes are still a Stage 3 proposal and may change in the future.fixKeep the library updated to adapt to spec changes.
affects: all
Errors
Common errors & fixes
Error: require() of ES Module not supported
Using require() to import the ESM-only package
fixUse import syntax or convert your project to ESM (type:'module' in package.json).
Missing: with {type: 'macro'} - Unexpected token
The import attribute syntax is not parsed by the current bundler/transpiler
fixUse a tool that supports import attributes (e.g., Node >= 18, modern bundlers) or transpile with SWC/Babel plugin.
Error: Cannot find module 'unplugin-parcel-macros'
Package not installed
fixRun npm install unplugin-parcel-macros --save-dev
Audit
Dependencies
unpluginrequiredUnplugin is the core library providing the plugin interface for all bundlers