{"record":{"id":"10847e3bd3fde203","repo":"jackwener/OpenCLI","slug":"npm-package-name-value-is-not-a-valid-registr","errorCode":null,"errorMessage":"npm package name \"${value}\" is not a valid registry name","messagePattern":"npm package name \"(.+?)\" is not a valid registry name","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/npm/utils.js","lineNumber":25,"sourceCode":"const UA = 'opencli-npm-adapter (+https://github.com/jackwener/opencli)';\n\n// npm package names: 1-214 chars, lowercase letters/numbers/-._ , scoped form `@scope/name`.\nconst PKG_NAME = /^(?:@[a-z0-9][a-z0-9._-]*\\/)?[a-z0-9][a-z0-9._-]*$/i;\n\nexport function requireString(value, label) {\n    const s = String(value ?? '').trim();\n    if (!s) throw new ArgumentError(`npm ${label} cannot be empty`);\n    return s;\n}\n\nexport function requirePackageName(value) {\n    const s = String(value ?? '').trim();\n    if (!s) throw new ArgumentError('npm package name is required (e.g. \"react\", \"@vercel/og\")');\n    if (s.length > 214) {\n        throw new ArgumentError(`npm package name \"${value}\" is too long (max 214 chars)`);\n    }\n    if (!PKG_NAME.test(s)) {\n        throw new ArgumentError(\n            `npm package name \"${value}\" is not a valid registry name`,\n            'Names are 1–214 chars of lowercase a-z / 0-9 / \"-._\" (scoped form: \"@scope/name\").',\n        );\n    }\n    return s;\n}\n\nexport function requireBoundedInt(value, defaultValue, maxValue, label = 'limit') {\n    const raw = value ?? defaultValue;\n    const n = typeof raw === 'number' ? raw : Number(raw);\n    if (!Number.isInteger(n) || n <= 0) {\n        throw new ArgumentError(`npm ${label} must be a positive integer`);\n    }\n    if (n > maxValue) {\n        throw new ArgumentError(`npm ${label} must be <= ${maxValue}`);\n    }\n    return n;\n}","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/npm/utils.js#L7-L43","documentation":"requirePackageName validates the name against PKG_NAME — the npm name grammar (optional scoped `@scope/name`, 1-214 chars of lowercase letters, digits, '-', '.', '_') — and throws ArgumentError `is not a valid registry name` with a hint when the pattern fails. This mirrors npm's new-package naming rules, so invalid syntax never reaches the registry.","triggerScenarios":"Names with illegal characters or structure: spaces, more than one '/', a leading '.', '_' or '-', '@' not starting a scope, bare `@scope` without `/name`, URLs, semicolons, or other punctuation outside [-._].","commonSituations":"Passing `@vercel` alone without `/og`; passing a URL or file path; names with spaces from unquoted shell args; legacy uppercase-only names tested against new-package rules; shell-mangled names.","solutions":["Fix the name to npm's grammar: `react`, `lodash`, `@scope/name` — lowercase letters, digits, '-', '.', '_' only.","For legacy names with uppercase, resolve the current lowercase name via `npm view`.","Strip protocol/path prefixes before passing the name.","Catch ArgumentError and show the provided hint text to guide the user."],"exampleFix":"// before\nawait npmPackage({ name: '@vercel' });     // invalid: scope without /name\nawait npmPackage({ name: 'my package' });  // invalid: space\n// after\nawait npmPackage({ name: '@vercel/og' });\nawait npmPackage({ name: 'mypackage' });","handlingStrategy":"validation","validationCode":"const PKG_NAME = /^(?:@[a-z0-9][a-z0-9._-]*\\/)?[a-z0-9][a-z0-9._-]*$/i;\nfunction isValidNpmName(v) {\n  const s = String(v ?? '').trim();\n  return s.length >= 1 && s.length <= 214 && PKG_NAME.test(s);\n}\nif (!isValidNpmName(args.name)) throw new Error('Names are 1-214 chars of a-z/0-9/-._ (scoped: @scope/name)');","typeGuard":"function isScopedName(v) {\n  return typeof v === 'string' && /^@[a-z0-9][a-z0-9._-]*\\/[a-z0-9][a-z0-9._-]*$/i.test(v.trim());\n}","tryCatchPattern":"try {\n  return await npmPackage({ name });\n} catch (e) {\n  if (e.name === 'ArgumentError' && /not a valid registry name/.test(e.message)) {\n    console.error('Use npm name syntax: react, lodash, @scope/name');\n    return null;\n  }\n  throw e;\n}","preventionTips":["Run the npm name regex on user input before calling the library.","Strip protocol/path prefixes and quotes from pasted values.","Ensure scoped names include both @scope and /name parts.","Reuse the library's own PKG_NAME pattern in your validation layer."],"tags":["validation","argument-error","npm","package-name-format","regex"],"backgroundTag":"invalid-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}