{"record":{"id":"b63e949b1229d316","repo":"nodejs/node","slug":"package-name-must-be-specified-either-as-an-argume-b63e94","errorCode":null,"errorMessage":"Package name must be specified either as an argument or in package.json file","messagePattern":"Package name must be specified either as an argument or in package\\.json file","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"deps/npm/lib/trust-cmd.js","lineNumber":273,"sourceCode":"    const usedPkgNameFromPkgJson = !pkgPositional && Boolean(pkgJsonName)\n    const invalidPkgJsonProviderType = matchPkg && git && git?.type !== name\n\n    let entity\n    let entitySource\n\n    if (flags[entityKey]) {\n      entity = flags[entityKey]\n      entitySource = 'flag'\n    } else if (!invalidPkgJsonProviderType && git?.repository) {\n      entity = git.repository\n      entitySource = 'package.json'\n    }\n    const mismatchPkgJsonRepository = matchPkg && git && entity !== git.repository\n    const usedRepositoryInPkgJson = entitySource === 'package.json'\n\n    const warnings = []\n    if (!pkgName) {\n      throw new Error('Package name must be specified either as an argument or in package.json file')\n    }\n\n    if (!flags.file) {\n      throw new Error(`${providerFile} must be specified with the file option`)\n    }\n    if (!flags.file.endsWith('.yml') && !flags.file.endsWith('.yaml')) {\n      throw new Error(`${providerFile} must end in .yml or .yaml`)\n    }\n\n    this.validateFile?.(flags.file)\n\n    if (invalidPkgJsonProviderType) {\n      const message = this.warnString`Repository in package.json is not a ${providerEntity}`\n      if (!flags[entityKey]) {\n        throw new Error(message)\n      } else {\n        warnings.push(message)\n      }","sourceCodeStart":255,"sourceCodeEnd":291,"githubUrl":"https://github.com/nodejs/node/blob/1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e/deps/npm/lib/trust-cmd.js#L255-L291","documentation":"Thrown by TrustCommand.flagsToOptions when neither a positional package name nor a package.json `name` field is available. Identical root cause to error 62/63 but reached via the create flow: pkgName = pkgPositional || pkgJsonName, and both are undefined. The guard fires before file/entity checks, so it is the first thing flagsToOptions validates.","triggerScenarios":"Running `npm trust <provider> --file ... --project ...` from a directory with no package.json (or one missing `name`) and no positional package argument. optionalPkgJson returns {} on read failure.","commonSituations":"Setting up trust for a package whose checkout isn't present; running from a docs/scripts folder; a scaffolded package.json without a name yet.","solutions":["Pass the package name as the first positional: `npm trust gitlab @scope/pkg --file ... --project ...`.","Add a `name` field to the local package.json.","Run the command from the package root that contains a valid package.json."],"exampleFix":"// before\nnpm trust gitlab --file .gitlab-ci.yml --project g/p --allow-publish\n// after\nnpm trust gitlab @scope/pkg --file .gitlab-ci.yml --project g/p --allow-publish","handlingStrategy":"validation","validationCode":"const pkgName = positionalArg || (await readPkgJsonSafe()).name\nif (!pkgName) {\n  throw new Error('Provide the package name positionally or via package.json#name')\n}","typeGuard":"const hasUsableName = (positional, pkg) =>\n  Boolean(positional) || Boolean(pkg && pkg.name)","tryCatchPattern":"try {\n  await createConfigCommand(...)\n} catch (err) {\n  if (/Package name must be specified/i.test(err.message)) {\n    // supply a positional package name and retry\n  } else { throw err }\n}","preventionTips":["Pass the package name as the first positional when scripting trust creation.","Ensure package.json in cwd has a `name` field.","Run from the package's own checkout directory."],"tags":["validation","trust","cli-args","package-json"],"backgroundTag":null,"analyzedSha":"1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e","analyzedAt":"2026-08-13T00:53:24.642Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}