Registry / devops / rollup-plugin-consts

rollup-plugin-consts

JSON →
library1.2.0jsnpmunverified

Import build-time constants (e.g., NODE_ENV, version) as ES module imports in Rollup. Unlike string-replacement plugins (rollup-plugin-replace), it uses a virtual module prefix 'consts:' for cleaner code and TypeScript support. Latest version 1.2.0, stable and unmaintained since 2020. Ships with TypeScript types. Peer dep rollup >=1.15.0 <4. ESM-only, no CommonJS.

npm install rollup-plugin-consts
INSTALL
IMPORT
SIG · ROLLUP-PLUGIN-CONS
R
rollup-plugin-consts
devopsjavascriptv1.2.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
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
musl
node 18223 runs
build_error
glibc
node 18223 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);
Debug
Known issues
breakingrollup-plugin-consts is incompatible with Rollup 4+. Peer dependency specifies rollup >=1.15.0 <4.
fix
Use an alternative like @rollup/plugin-replace or migrate to a newer plugin.
affects: >=1.0.0
deprecatedPackage has not been updated since 2020. May not receive fixes for future Rollup versions.
fix
Consider using @rollup/plugin-replace or rollup-plugin-swc with define.
affects: >=1.0.0
gotchaConstants are evaluated at build time and must be serializable (strings, booleans, objects). Functions or complex expressions are not supported.
fix
Pass only plain JSON-serializable values as constants.
affects: >=1.0.0
gotchaVirtual modules use the 'consts:' prefix and must be explicitly listed in TypeScript declarations.
fix
Create a .d.ts file, e.g., declare module 'consts:*' { const value: any; export default value; }
affects: >=1.0.0
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.
fix
Ensure 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.
fix
Use 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.
fix
Pass only strings, numbers, booleans, arrays, or plain objects as constant values.
Upgrade
Version history
1.2.0latest on npm
Audit
Dependencies
rolluprequiredPeer dependency: requires Rollup >=1.15.0 <4
Agent activity
7 hits · last 30 days
node
6
Resources
rollup-plugin-consts — npm install rollup-plugin-consts · libregistry