{"id":"26023e74aae97c2a","repo":"rollup/rollup","slug":"invalid-plugin-argument-format-json-stringify","errorCode":null,"errorMessage":"Invalid --plugin argument format: ${JSON.stringify(pluginText)}","messagePattern":"Invalid --plugin argument format: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/run/commandPlugins.ts","lineNumber":60,"sourceCode":"\nasync function loadAndRegisterPlugin(\n\tinputOptions: InputOptionsWithPlugins,\n\tpluginText: string\n): Promise<void> {\n\tlet plugin: any = null;\n\tlet pluginArgument: any = undefined;\n\tif (pluginText[0] === '{') {\n\t\t// -p \"{transform(c,i){...}}\"\n\t\tplugin = new Function('return ' + pluginText);\n\t} else {\n\t\tconst match = pluginText.match(/^([\\w./:@\\\\^{|}-]+)(=(.*))?$/);\n\t\tif (match) {\n\t\t\t// -p plugin\n\t\t\t// -p plugin=arg\n\t\t\tpluginText = match[1];\n\t\t\tpluginArgument = new Function('return ' + match[3])();\n\t\t} else {\n\t\t\tthrow new Error(`Invalid --plugin argument format: ${JSON.stringify(pluginText)}`);\n\t\t}\n\t\tif (!/^\\.|^rollup-plugin-|[/@\\\\]/.test(pluginText)) {\n\t\t\t// Try using plugin prefix variations first if applicable.\n\t\t\t// Prefix order is significant - left has higher precedence.\n\t\t\tfor (const prefix of ['@rollup/plugin-', 'rollup-plugin-']) {\n\t\t\t\ttry {\n\t\t\t\t\tplugin = await requireOrImport(prefix + pluginText);\n\t\t\t\t\tbreak;\n\t\t\t\t} catch {\n\t\t\t\t\t// if this does not work, we try requiring the actual name below\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (!plugin) {\n\t\t\ttry {\n\t\t\t\tif (pluginText[0] == '.') pluginText = path.resolve(pluginText);\n\t\t\t\t// Windows absolute paths must be specified as file:// protocol URL\n\t\t\t\t// Note that we do not have coverage for Windows-only code paths","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/rollup/rollup/blob/ddc4ffab628944e45dbb8d66d58aae818015440f/cli/run/commandPlugins.ts#L42-L78","documentation":"Thrown by the Rollup CLI when the text passed to --plugin/-p does not look like a module specifier, a `name=arg` pair, or an inline object literal. The loader at cli/run/commandPlugins.ts:53 only accepts the regex `/^[\\w./:@\\\\^{|}-]+(=(.*))?$/` once the leading `{` case is ruled out; any character outside that class (spaces, +, %, etc.) makes the argument unparseable.","triggerScenarios":"Running `rollup -p \"node resolve\"` (space), `rollup -p \"a+b\"`, `rollup -p \"foo#bar\"`, or any plugin string containing characters outside `[\\w./:@\\\\^{|}-]` that does not start with `{`.","commonSituations":"Shell quoting mistakes, copy-pasted plugin names with stray spaces, attempting to pass JSON-like option strings without the leading brace, or trying to pass multiple plugins separated by spaces instead of commas.","solutions":["Remove characters outside [\\w./:@\\^{|}-] from the plugin argument (most often: stray spaces).","Pass inline object plugins with a leading brace: -p \"{ transform(code, id) { return code } }\".","Pass plugin options via `=`: -p node-resolve={browser:true}.","Separate multiple plugins with commas: -p node-resolve,commonjs.","Use a rollup.config.js file instead of -p for non-trivial plugin configuration."],"exampleFix":"// before\nrollup -p \"node resolve\"\n\n// after\nrollup -p node-resolve","handlingStrategy":"validation","validationCode":"// Reject invalid --plugin text before invoking the CLI loader.\nconst PLUGIN_SPEC_RE = /^[\\w./:@\\\\^{|}-]+(=(.*))?$/;\nfunction isValidPluginText(text) {\n  if (typeof text !== 'string' || text.length === 0) return false;\n  if (text[0] === '{') return true; // inline object plugin\n  return PLUGIN_SPEC_RE.test(text);\n}\nif (!isValidPluginText(userPluginArg)) {\n  throw new Error(`Refusing to run: bad --plugin value ${JSON.stringify(userPluginArg)}`);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Quote -p arguments to avoid shell splitting on spaces.","Use rollup.config.js for anything beyond a simple plugin name.","Separate multiple plugins with commas, not spaces.","Pass inline plugins with a leading `{` and options via `=`."],"tags":["cli","plugin","config","validation"],"analyzedSha":"ddc4ffab628944e45dbb8d66d58aae818015440f","analyzedAt":"2026-08-03T19:42:57.546Z","schemaVersion":2}