{"record":{"id":"764215f365eb1971","repo":"nodejs/node","slug":"npm-rebuild-only-supports-semver-version-range-s","errorCode":null,"errorMessage":"`npm rebuild` only supports SemVer version/range specifiers","messagePattern":"`npm rebuild` only supports SemVer version/range specifiers","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"deps/npm/lib/commands/rebuild.js","lineNumber":56,"sourceCode":"    const arb = new Arborist({\n      ...this.npm.flatOptions,\n      path: where,\n      allowScripts: allowScriptsPolicy,\n      // TODO when extending ReifyCmd\n      // workspaces: this.workspaceNames,\n    })\n\n    if (args.length) {\n      // get the set of nodes matching the name that we want rebuilt\n      const tree = await arb.loadActual()\n      const specs = args.map(arg => {\n        const spec = npa(arg)\n        if (spec.rawSpec === '*') {\n          return spec\n        }\n\n        if (spec.type !== 'range' && spec.type !== 'version' && spec.type !== 'directory') {\n          throw new Error('`npm rebuild` only supports SemVer version/range specifiers')\n        }\n\n        return spec\n      })\n      const nodes = [...tree.inventory.filter(node => this.isNode(specs, node))]\n\n      await strictAllowScriptsPreflight({ arb, npm: this.npm })\n      await arb.rebuild({ nodes })\n    } else {\n      await arb.loadActual()\n      await strictAllowScriptsPreflight({ arb, npm: this.npm })\n      await arb.rebuild()\n    }\n\n    // Phase 1 advisory: list any packages whose install scripts ran (or\n    // would have run) and are not yet covered by allowScripts. Rebuild\n    // doesn't go through reifyFinish, so the walker is invoked here.\n    const unreviewed = await checkAllowScripts({ arb, npm: this.npm })","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/nodejs/node/blob/1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e/deps/npm/lib/commands/rebuild.js#L38-L74","documentation":"Thrown by `npm rebuild` when one of the positional arguments, parsed by `npa`, resolves to a spec type other than `range`, `version`, or `directory` (and is not the bare `*`). npm rebuild only knows how to select installed packages by SemVer range/version or a local directory path; git/tag/alias/remote specs are unsupported.","triggerScenarios":"Calling `npm rebuild <arg>` where `npa(arg).type` is `git`, `tag`, `alias`, `remote`, or similar, and `.rawSpec !== '*'`.","commonSituations":"Trying `npm rebuild github:owner/repo`, `npm rebuild pkg@next` (a dist-tag), or `npm rebuild https://...tarball`; copy-pasting an install-style spec into rebuild.","solutions":["Use a SemVer range or exact version, e.g. `npm rebuild lodash@4.17.21` or `npm rebuild lodash@^4`.","Rebuild by package name only (`npm rebuild lodash`) which yields a `*` spec and is allowed.","Point at a local directory: `npm rebuild ./my-local-dep`.","If you need a git/tag package rebuilt, install it first, then rebuild by name."],"exampleFix":"// before\nnpm rebuild lodash@next\n// after\nnpm rebuild lodash","handlingStrategy":"validation","validationCode":"const npa = require('npm-package-arg')\nfunction assertRebuildSpec(arg) {\n  const spec = npa(arg)\n  if (spec.rawSpec === '*') return spec\n  if (!['range', 'version', 'directory'].includes(spec.type)) {\n    throw new Error(`npm rebuild needs a SemVer range/version or directory, got ${spec.type} for \"${arg}\"`)\n  }\n  return spec\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Rebuild by bare package name (`npm rebuild lodash`) whenever possible.","Never pass git/tag/URL specs to `npm rebuild`; install them first.","Validate rebuild args in release scripts with the snippet above."],"tags":["rebuild","npa","semver","npm-cli","argument-validation"],"backgroundTag":null,"analyzedSha":"1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e","analyzedAt":"2026-08-13T00:53:24.642Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}