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.
consts
✓ import consts from 'rollup-plugin-consts'
✗ const { consts } = require('rollup-plugin-consts')
Default export only; CommonJS require() cannot destructure default export.
environment (consts:environment)
✓ import environment from 'consts:environment'
✗ import environment from 'rollup-plugin-consts'
Constants are virtual modules prefixed with 'consts:'. Do not import from the plugin package itself.
config (consts:config)
✓ import config from 'consts:config'
✗ import { config } from 'consts:config'
Virtual modules are default exports; named destructuring does not work.
Shows how to set up the plugin in rollup.config.js and use imported constants from virtual modules.
// rollup.config.js
import consts from 'rollup-plugin-consts';
export default {
input: 'src/index.js',
output: { file: 'dist/bundle.js', format: 'es' },
plugins: [
consts({
environment: 'production',
version: '1.0.0',
config: { names: ['foo', 'bar'] }
})
]
};
// src/index.js
import environment from 'consts:environment';
import version from 'consts:version';
import config from 'consts:config';
console.log(environment, version, config.names);
Errors
Common errors & fixes
Error: Cannot find module 'consts:environment'
The plugin is not registered in the rollup config plugins array or is placed after other plugins that cache resolution.
fixEnsure consts() is called in the rollup plugins array and that it appears early (before plugins like commonjs).
[!] TypeError: consts is not a function
Using a named import instead of default import, or using CommonJS require without .default.
fixUse the default import: import consts from 'rollup-plugin-consts';
RollupError: Unexpected token (Note that you need plugins to import files that are not JavaScript)
The constant value contains a non-JSON literal (e.g., a function) that Rollup cannot parse as JavaScript.
fixPass only strings, numbers, booleans, arrays, or plain objects as constant values.
Audit
Dependencies
rolluprequiredPeer dependency: requires Rollup >=1.15.0 <4