{"id":22320,"library":"rollup-utils","title":"rollup-utils","description":"A set of utility functions for Rollup plugins, forked from @rollup/pluginutils but using path-browserify instead of the Node.js path module to support browser environments. Version 0.0.5 (released on npm, but no release cadence noted). Requires Node >=14.0.0 and Rollup ^1.20.0||^2.0.0||^3.0.0||^4.0.0. Ships TypeScript type definitions. Key differentiators from @rollup/pluginutils: browser compatibility via path-browserify dependency. Includes addExtension, attachScopes, createFilter, dataToEsm, extractAssignedNames, makeLegalIdentifier, and normalizePath functions.","status":"active","version":"0.0.5","language":"javascript","source_language":"en","source_url":"https://github.com/zhiyuanzmj/rollup-utils","tags":["javascript","rollup","plugin","utils","typescript"],"install":[{"cmd":"npm install rollup-utils","lang":"bash","label":"npm"},{"cmd":"yarn add rollup-utils","lang":"bash","label":"yarn"},{"cmd":"pnpm add rollup-utils","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Replaces Node.js 'path' module for browser compatibility","package":"path-browserify","optional":false}],"imports":[{"note":"Package is ESM-only (ES module). CommonJS require() will cause an error.","wrong":"const utils = require('rollup-utils');","symbol":"* as utils","correct":"import * as utils from 'rollup-utils';"},{"note":"Named export, not default export. Use named import syntax.","wrong":"const addExtension = require('rollup-utils').addExtension;","symbol":"addExtension","correct":"import { addExtension } from 'rollup-utils';"},{"note":"createFilter is a named export, not default. Incorrect as default import.","wrong":"import createFilter from 'rollup-utils';","symbol":"createFilter","correct":"import { createFilter } from 'rollup-utils';"},{"note":"attachScopes is from 'rollup-utils', not '@rollup/pluginutils' (though the API is similar).","wrong":"import { attachScopes } from '@rollup/pluginutils';","symbol":"attachScopes","correct":"import { attachScopes } from 'rollup-utils';"},{"note":"Named export; use exactly as shown.","wrong":null,"symbol":"dataToEsm","correct":"import { dataToEsm } from 'rollup-utils';"}],"quickstart":{"code":"import { createFilter } from 'rollup-utils';\nimport resolve from '@rollup/plugin-node-resolve';\n\nexport default {\n  input: 'src/index.js',\n  output: { dir: 'dist', format: 'es' },\n  plugins: [\n    resolve(),\n    {\n      name: 'my-plugin',\n      transform(code, id) {\n        const filter = createFilter('src/**/*.js', 'node_modules/**');\n        if (!filter(id)) return null;\n        // Transform only included modules\n        return code.replace(/__VERSION__/g, '1.0.0');\n      }\n    }\n  ]\n};","lang":"typescript","description":"Shows how to import createFilter and use it in a Rollup plugin's transform hook to include only specific module IDs."},"warnings":[{"fix":"Use import syntax instead of require().","message":"Breaking change: package is ESM-only. CommonJS require() will throw an error.","severity":"breaking","affected_versions":">=0.0.0"},{"fix":"Ensure you pass a string ID (e.g., the module path).","message":"createFilter returns a function that expects a string or unknown id, not an object. Passing an object may silently return false.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Check filename before calling addExtension if you want to force extension addition.","message":"addExtension does not add an extension if the filename already has an extension (including '.' only).","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Call attachScopes once on the AST, then walk and manage scope manually.","message":"attachScopes requires the AST to already have 'scope' property attached to nodes; it mutates the AST.","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Switch to import syntax (e.g., import { createFilter } from 'rollup-utils').","cause":"Using CommonJS require() on an ESM-only package.","error":"Error [ERR_REQUIRE_ESM]: require() of ES Module /path/to/rollup-utils/dist/index.js from /path/to/index.js not supported."},{"fix":"Use import { createFilter } from 'rollup-utils' instead of import createFilter from 'rollup-utils'.","cause":"Incorrect import style, probably using default import when createFilter is named export.","error":"TypeError: (0 , _rollupUtils.createFilter) is not a function"},{"fix":"Ensure rollup is installed: npm install rollup --save-dev","cause":"rollup is a peer dependency and not installed automatically.","error":"Cannot find module 'rollup'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}