{"record":{"id":"2b31e9a0c477f479","repo":"nodejs/node","slug":"package-name-must-be-specified-either-as-an-argume-2b31e9","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/revoke.js","lineNumber":32,"sourceCode":"    '[package] --id=<trust-id>',\n  ]\n\n  static definitions = [\n    new Definition('id', {\n      default: null,\n      type: String,\n      description: 'ID of the trusted relationship to revoke',\n      required: true,\n    }),\n    globalDefinitions['dry-run'],\n    globalDefinitions.registry,\n  ]\n\n  async exec (positionalArgs, flags) {\n    const dryRun = this.config.get('dry-run')\n    const pkgName = positionalArgs[0] || (await this.optionalPkgJson()).name\n    if (!pkgName) {\n      throw new Error('Package name must be specified either as an argument or in the package.json file')\n    }\n    const { id } = flags\n    if (!id) {\n      throw new Error('ID of the trusted relationship to revoke must be specified with the --id option')\n    }\n    this.dialogue`Attempting to revoke trusted configuration for package ${pkgName} with id ${id}`\n    if (dryRun) {\n      return\n    }\n    const spec = npa(pkgName)\n    const uri = `/-/package/${spec.escapedName}/trust/${encodeURIComponent(id)}`\n    await otplease(this.npm, this.npm.flatOptions, opts => npmFetch(uri, {\n      ...opts,\n      method: 'DELETE',\n    }))\n    this.dialogue`Revoked trusted configuration for package ${pkgName} with id ${id}`\n  }\n}","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/nodejs/node/blob/1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e/deps/npm/lib/commands/trust/revoke.js#L14-L50","documentation":"Thrown by `npm trust revoke` when neither a positional package name nor a resolvable package.json `name` is available. revoke needs the escaped name to DELETE `/-/package/<escapedName>/trust/<id>`. optionalPkgJson returns {} on any read failure so pkgName stays undefined.","triggerScenarios":"Running `npm trust revoke --id <id>` from a directory with no package.json or one lacking a name; forgetting the positional argument.","commonSituations":"Revoking a trust relationship for a package whose checkout you no longer have open; running from a CI working dir that only checked out a subpath; script automation that omits the positional.","solutions":["Pass the package name positionally: `npm trust revoke <pkg> --id <id>`.","Run inside the package's own directory so package.json provides the name.","Add/restore the `name` field in the local package.json."],"exampleFix":"// before\nnpm trust revoke --id abc123\n// after\nnpm trust revoke @my-scope/my-pkg --id abc123","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 before revoking')\n}","typeGuard":"const hasUsableName = (positional, pkg) =>\n  Boolean(positional) || Boolean(pkg && pkg.name)","tryCatchPattern":"try {\n  await trustRevoke.exec([maybePkg], { id })\n} catch (err) {\n  if (/Package name must be specified/i.test(err.message)) {\n    // supply positional package and retry\n  } else { throw err }\n}","preventionTips":["Pass the package name positionally in revoke scripts.","Confirm you are in the package's own directory when relying on package.json.","Validate inputs in your automation before calling the command."],"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"}