{"record":{"id":"42397b82ae982691","repo":"nodejs/node","slug":"invalid-package-json-no-name-field","errorCode":null,"errorMessage":"Invalid package.json, no \"name\" field","messagePattern":"Invalid package\\.json, no \"name\" field","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"deps/npm/lib/commands/view.js","lineNumber":63,"sourceCode":"    const pckmnt = await packument(spec, config)\n    const defaultTag = npm.config.get('tag')\n    const dv = pckmnt.versions[pckmnt['dist-tags'][defaultTag]]\n    pckmnt.versions = Object.keys(pckmnt.versions).sort(semver.compareLoose)\n\n    return getCompletionFields(pckmnt).concat(getCompletionFields(dv))\n  }\n\n  async exec (args) {\n    let { pkg, local, rest } = parseArgs(args)\n\n    if (local) {\n      if (this.npm.global) {\n        throw new Error('Cannot use view command in global mode.')\n      }\n      const dir = this.npm.prefix\n      const manifest = await readJson(resolve(dir, 'package.json'))\n      if (!manifest.name) {\n        throw new Error('Invalid package.json, no \"name\" field')\n      }\n      // put the version back if it existed\n      pkg = `${manifest.name}${pkg.slice(1)}`\n    }\n\n    await this.#viewPackage(pkg, rest)\n  }\n\n  async execWorkspaces (args) {\n    const { pkg, local, rest } = parseArgs(args)\n\n    if (!local) {\n      log.warn('Ignoring workspaces for specified package(s)')\n      return this.exec([pkg, ...rest])\n    }\n\n    const json = this.npm.config.get('json')\n    await this.setWorkspaces()","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/nodejs/node/blob/1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e/deps/npm/lib/commands/view.js#L45-L81","documentation":"Thrown by `npm view` in local mode after successfully reading the directory's package.json but finding no `name` field. Without a name, view cannot construct a package spec to query the registry. This is a package.json validity error, not a registry error.","triggerScenarios":"`npm view .` (or bare view) where the current package.json parses but has no top-level `name`. Common with private root manifests, boilerplate scaffolds, or partially-edited files.","commonSituations":"A monorepo root package.json marked private with only a workspaces field and no name; a freshly initialized package before naming; an accidental deletion of the name line.","solutions":["Add a `name` field to the local package.json.","Run view from inside the leaf package directory that does have a name.","Specify the package explicitly: `npm view <pkg>` instead of using the local form."],"exampleFix":"// before\n// package.json: { \"version\": \"1.0.0\" }\nnpm view .\n// after\n// package.json: { \"name\": \"my-pkg\", \"version\": \"1.0.0\" }\nnpm view .","handlingStrategy":"validation","validationCode":"const manifest = JSON.parse(await readFile('package.json', 'utf8'))\nif (!manifest.name) {\n  throw new Error('package.json is missing a \"name\" field; cannot view locally')\n}","typeGuard":"const hasNameField = (manifest) =>\n  manifest != null && typeof manifest.name === 'string' && manifest.name.length > 0","tryCatchPattern":"try {\n  await view.exec(['.'])\n} catch (err) {\n  if (/no .name. field/i.test(err.message)) {\n    // read package.json, prompt user for a name, write it back, then retry\n  } else { throw err }\n}","preventionTips":["Always set a `name` in package.json when scaffolding a package.","Validate manifests in a preinstall lint step.","Use explicit package specs (`npm view <pkg>`) when local metadata is unreliable."],"tags":["validation","view","package-json"],"backgroundTag":null,"analyzedSha":"1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e","analyzedAt":"2026-08-13T00:53:24.642Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}