canirequire

canirequireCommonJS › rollup-plugin-json

Is rollup-plugin-json ESM-only? Can you require() it?

Convert .json files to ES6 modules:

Last verified Sep 9, 2026 against rollup-plugin-json@4.0.0. JSON

CommonJS CommonJS — require() works on every Node.js version

rollup-plugin-json ships CommonJS only. require("rollup-plugin-json") works everywhere. import "rollup-plugin-json" also works because Node.js and Bun can import CommonJS from ES modules, but only the default export is guaranteed; named imports depend on Node's static analysis of the module.

It also declares a "module" field, so bundlers such as webpack, Vite and esbuild pick up an ESM build for tree-shaking.

Latest
4.0.0 (Mar 18, 2019)
Module format
CommonJS
Last CommonJS version
4.0.0
TypeScript types
@types/rollup-plugin-json
Node engines
not declared
Weekly downloads
121K
License
MIT

Deprecated: This module has been deprecated and is no longer maintained. Please use @rollup/plugin-json.

Does rollup-plugin-json@4.0.0 actually load? Runtime test results

Installed and executed on Sep 9, 2026 with require("rollup-plugin-json") from a CommonJS file and import "rollup-plugin-json" from an ES module.

Runtimerequire("rollup-plugin-json")import "rollup-plugin-json"
Node.js 18✓ works✓ works
Node.js 20✓ works✓ works
Node.js 22✓ works✓ works
Node.js 24✓ works✓ works
Node.js 26✓ works✓ works
Bun 1.4✓ works✓ works

How to import rollup-plugin-json

ES modules (import)

import rollupPluginJson from "rollup-plugin-json";

Named imports from a CommonJS package only work when Node.js can statically detect them. If a named import fails, use the default import and destructure.

CommonJS (require)

const rollupPluginJson = require("rollup-plugin-json");

Module format by version

Derived from the type, main and exports fields of every stable release on npm (12 versions; the newest 12 shown).

VersionsFormatFirst published
1.0.0 – 4.0.0CommonJSOct 25, 2015

Frequently asked

Is rollup-plugin-json ESM-only?

rollup-plugin-json@4.0.0 is a CommonJS package. rollup-plugin-json ships CommonJS only. require("rollup-plugin-json") works everywhere. import "rollup-plugin-json" also works because Node.js and Bun can import CommonJS from ES modules, but only the default export is guaranteed; named imports depend on Node's static analysis of the module.

Can I import rollup-plugin-json with ES module syntax?

Yes. import rollupPluginJson from "rollup-plugin-json" works in Node.js and Bun because they support importing CommonJS modules. Named imports work only when Node.js can statically detect the exports.

Does rollup-plugin-json work in Bun?

Yes. import "rollup-plugin-json" loaded successfully in Bun 1.4 on Sep 9, 2026.

Does rollup-plugin-json ship TypeScript types?

Not bundled. Install the community types with "npm install -D @types/rollup-plugin-json".

Links

Other commonjs packages

Similar popularity