{"record":{"id":"365089fc88c5e479","repo":"nodejs/node","slug":"package-name-must-be-specified-either-as-an-argume-365089","errorCode":null,"errorMessage":"Package name must be specified either as an argument or in the package.json file","messagePattern":"Package name must be specified either as an argument or in the package\\.json file","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"deps/npm/lib/commands/trust/list.js","lineNumber":38,"sourceCode":"    globalDefinitions.json,\n    globalDefinitions.registry,\n  ]\n\n  static bodyToOptions (body) {\n    if (body.type === 'circleci') {\n      return TrustCircleCI.bodyToOptions(body)\n    } else if (body.type === 'github') {\n      return TrustGithub.bodyToOptions(body)\n    } else if (body.type === 'gitlab') {\n      return TrustGitlab.bodyToOptions(body)\n    }\n    return TrustCommand.bodyToOptions(body)\n  }\n\n  async exec (positionalArgs) {\n    const packageName = positionalArgs[0] || (await this.optionalPkgJson()).name\n    if (!packageName) {\n      throw new Error('Package name must be specified either as an argument or in the package.json file')\n    }\n    const spec = npa(packageName)\n    const uri = `/-/package/${spec.escapedName}/trust`\n    const body = await otplease(this.npm, this.npm.flatOptions, opts => npmFetch.json(uri, {\n      ...opts,\n      method: 'GET',\n    }))\n    this.displayResponseBody({ body, packageName })\n  }\n}\n\nmodule.exports = TrustList\n","sourceCodeStart":20,"sourceCodeEnd":51,"githubUrl":"https://github.com/nodejs/node/blob/1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e/deps/npm/lib/commands/trust/list.js#L20-L51","documentation":"Thrown by `npm trust list` when no package name was given as the first positional argument AND the optional package.json in the current directory has no `name` field (or no package.json exists). The command needs a name to build the registry URI `/-/package/<escapedName>/trust`. optionalPkgJson swallows read errors and returns {}, so .name is undefined.","triggerScenarios":"Running `npm trust list` in an empty dir, a scratch dir without package.json, or a package.json missing the `name` field. Also when the package.json is malformed enough that normalize yields no name.","commonSituations":"Exploring trust features outside a project; running from a config-only directory; a monorepo child that has dependencies but no name set yet.","solutions":["Pass the package name explicitly: `npm trust list lodash`.","Add a `name` field to the local package.json and rerun.","Run the command from the package root that owns the package.json."],"exampleFix":"// before\nnpm trust list\n// after\nnpm trust list @my-scope/my-pkg","handlingStrategy":"validation","validationCode":"const pkgName = positionalArg || (await readPkgJsonSafe()).name\nif (!pkgName) {\n  throw new Error('Package name must be supplied as the first argument or via package.json#name')\n}\nfunction readPkgJsonSafe() { try { return require('./package.json') } catch { return {} } }","typeGuard":"const hasUsableName = (positional, pkg) =>\n  Boolean(positional) || Boolean(pkg && typeof pkg.name === 'string' && pkg.name.length)","tryCatchPattern":"try {\n  await trustList.exec([maybePkg])\n} catch (err) {\n  if (/Package name must be specified/i.test(err.message)) {\n    // fall back to an explicit package argument and retry\n  } else { throw err }\n}","preventionTips":["Always pass an explicit package name when scripting `npm trust list`.","Ensure the local package.json has a `name` field before relying on it.","Run trust commands from the package root."],"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"}