# Npm-rebuild

日常开发中 经常遇见`npm install`失败后再怎么install都不成功问题，在那儿install磨叽半天 么得结果，有一天队友上来一个命令教做人了，那就是`npm rebuild`。那这样就得来看`rebuild`是什么操作了。 使用：

> npm rebuild \[\[@scope/name]...]

官方是这样说的：

> This command runs the `npm build` command on the matched folders. This is useful when you install a new version of node, and must recompile all your C++ addons with the new binary.

意思就是`rebuild`命令其实是在相应的目录运行了一下`build`命令（这不废话么，re-xxx不就是重复做xxx事么）。当你安装了新版本的node时，必须重新编译`C++`依赖。

所以最常见的场景是切换node版本时。

参考： [npm-rebuild](https://docs.npmjs.com/cli/rebuild)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://book.fezhao.com/npm/npm-rebuild.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
