@reggi/path-to-regexp
@reggi/path-to-regexp
dependabot/npm_and_yarn/main/copy-to-clipboard-4.0.2
dependabot/npm_and_yarn/main/eslint-10.4.0
dependabot/npm_and_yarn/main/npmcli/eslint-config-7.0.0
dependabot/npm_and_yarn/main/proc-log-7.0.0
dependabot/npm_and_yarn/npm_and_yarn-826852524d
dependabot/npm_and_yarn/npm_and_yarn-ab9a7f4bc2
deprecate-totp-2fa
dhei/classic-tokens
gat-bypass-2fa-docs
jpg619/fix-accessibility-content-flow
jpg619/version-bump-tar-2
kartykp/gat-bypass-2fa-docs
kartykp/upgrade-path-to-regex
main
maitxn/version-bump-tar
patch-1
reggi/cache-based-on-version
reggi/dev-engines
reggi/fix-transform-prettier
reggi/overrides
update-search-sensitivity
| 1 | --- |
| 2 | title: npm-rebuild |
| 3 | section: 1 |
| 4 | description: Rebuild a package |
| 5 | github_repo: npm/cli |
| 6 | github_branch: latest |
| 7 | github_path: docs/lib/content/commands/npm-rebuild.md |
| 8 | redirect_from: |
| 9 | - /cli-commands/npm-rebuild |
| 10 | - /cli-commands/rebuild |
| 11 | - /cli-documentation/cli-commands/npm-rebuild |
| 12 | - /cli-documentation/cli-commands/rebuild |
| 13 | - /cli-documentation/commands/npm-rebuild |
| 14 | - /cli-documentation/commands/rebuild |
| 15 | - /cli-documentation/npm-rebuild |
| 16 | - /cli-documentation/rebuild |
| 17 | - /cli-documentation/v11/cli-commands/npm-rebuild |
| 18 | - /cli-documentation/v11/cli-commands/rebuild |
| 19 | - /cli-documentation/v11/commands/npm-rebuild |
| 20 | - /cli-documentation/v11/commands/rebuild |
| 21 | - /cli-documentation/v11/npm-rebuild |
| 22 | - /cli-documentation/v11/rebuild |
| 23 | - /cli/cli-commands/npm-rebuild |
| 24 | - /cli/cli-commands/rebuild |
| 25 | - /cli/commands/npm-rebuild |
| 26 | - /cli/commands/rebuild |
| 27 | - /cli/npm-rebuild |
| 28 | - /cli/rebuild |
| 29 | - /cli/v11/cli-commands/npm-rebuild |
| 30 | - /cli/v11/cli-commands/rebuild |
| 31 | - /cli/v11/commands/rebuild |
| 32 | - /cli/v11/npm-rebuild |
| 33 | - /cli/v11/rebuild |
| 34 | - /commands/npm-rebuild |
| 35 | - /commands/rebuild |
| 36 | --- |
| 37 | |
| 38 | ### Synopsis |
| 39 | |
| 40 | ```bash |
| 41 | npm rebuild [<package-spec>] ...] |
| 42 | |
| 43 | alias: rb |
| 44 | ``` |
| 45 | |
| 46 | ### Description |
| 47 | |
| 48 | This command does the following: |
| 49 | |
| 50 | 1. Execute lifecycle scripts (`preinstall`, `install`, `postinstall`, `prepare`) |
| 51 | 2. Links bins depending on whether bin links are enabled |
| 52 | |
| 53 | This command is particularly useful in scenarios including but not limited to: |
| 54 | |
| 55 | 1. Installing a new version of **node.js**, where you need to recompile all your C++ add-ons with the updated binary. |
| 56 | 2. Installing with `--ignore-scripts` and `--no-bin-links`, to explicitly choose which packages to build and/or link bins. |
| 57 | |
| 58 | If one or more package specs are provided, then only packages with a name and version matching one of the specifiers will be rebuilt. |
| 59 | |
| 60 | Usually, you should not need to run `npm rebuild` as it is already done for you as part of npm install (unless you suppressed these steps with `--ignore-scripts` or `--no-bin-links`). |
| 61 | |
| 62 | If there is a `binding.gyp` file in the root of your package, then npm will use a default install hook: |
| 63 | |
| 64 | ``` |
| 65 | "scripts": { |
| 66 | "install": "node-gyp rebuild" |
| 67 | } |
| 68 | ``` |
| 69 | |
| 70 | This default behavior is suppressed if the `package.json` has its own `install` or `preinstall` scripts. It is also suppressed if the package specifies `"gypfile": false` |
| 71 | |
| 72 | ### Configuration |
| 73 | |
| 74 | #### `global` |
| 75 | |
| 76 | - Default: false |
| 77 | - Type: Boolean |
| 78 | |
| 79 | Operates in "global" mode, so that packages are installed into the `prefix` folder instead of the current working directory. See [folders](/cli/v11/configuring-npm/folders) for more on the differences in behavior. |
| 80 | |
| 81 | - packages are installed into the `{prefix}/lib/node_modules` folder, instead of the current working directory. |
| 82 | - bin files are linked to `{prefix}/bin` |
| 83 | - man pages are linked to `{prefix}/share/man` |
| 84 | |
| 85 | #### `bin-links` |
| 86 | |
| 87 | - Default: true |
| 88 | - Type: Boolean |
| 89 | |
| 90 | Tells npm to create symlinks (or `.cmd` shims on Windows) for package executables. |
| 91 | |
| 92 | Set to false to have it not do this. This can be used to work around the fact that some file systems don't support symlinks, even on ostensibly Unix systems. |
| 93 | |
| 94 | #### `foreground-scripts` |
| 95 | |
| 96 | - Default: `false` unless when using `npm pack` or `npm publish` where it defaults to `true` |
| 97 | - Type: Boolean |
| 98 | |
| 99 | Run all build scripts (ie, `preinstall`, `install`, and `postinstall`) scripts for installed packages in the foreground process, sharing standard input, output, and error with the main npm process. |
| 100 | |
| 101 | Note that this will generally make installs run slower, and be much noisier, but can be useful for debugging. |
| 102 | |
| 103 | #### `ignore-scripts` |
| 104 | |
| 105 | - Default: false |
| 106 | - Type: Boolean |
| 107 | |
| 108 | If true, npm does not run scripts specified in package.json files. |
| 109 | |
| 110 | Note that commands explicitly intended to run a particular script, such as `npm start`, `npm stop`, `npm restart`, `npm test`, and `npm run-script` will still run their intended script if `ignore-scripts` is set, but they will _not_ run any pre- or post-scripts. |
| 111 | |
| 112 | #### `workspace` |
| 113 | |
| 114 | - Default: |
| 115 | - Type: String (can be set multiple times) |
| 116 | |
| 117 | Enable running a command in the context of the configured workspaces of the current project while filtering by running only the workspaces defined by this configuration option. |
| 118 | |
| 119 | Valid values for the `workspace` config are either: |
| 120 | |
| 121 | - Workspace names |
| 122 | - Path to a workspace directory |
| 123 | - Path to a parent workspace directory (will result in selecting all workspaces within that folder) |
| 124 | |
| 125 | When set for the `npm init` command, this may be set to the folder of a workspace which does not yet exist, to create the folder and set it up as a brand new workspace within the project. |
| 126 | |
| 127 | This value is not exported to the environment for child processes. |
| 128 | |
| 129 | #### `workspaces` |
| 130 | |
| 131 | - Default: null |
| 132 | - Type: null or Boolean |
| 133 | |
| 134 | Set to true to run the command in the context of **all** configured workspaces. |
| 135 | |
| 136 | Explicitly setting this to false will cause commands like `install` to ignore workspaces altogether. When not set explicitly: |
| 137 | |
| 138 | - Commands that operate on the `node_modules` tree (install, update, etc.) will link workspaces into the `node_modules` folder. - Commands that do other things (test, exec, publish, etc.) will operate on the root project, _unless_ one or more workspaces are specified in the `workspace` config. |
| 139 | |
| 140 | This value is not exported to the environment for child processes. |
| 141 | |
| 142 | #### `include-workspace-root` |
| 143 | |
| 144 | - Default: false |
| 145 | - Type: Boolean |
| 146 | |
| 147 | Include the workspace root when workspaces are enabled for a command. |
| 148 | |
| 149 | When false, specifying individual workspaces via the `workspace` config, or all workspaces via the `workspaces` flag, will cause npm to operate only on the specified workspaces, and not on the root project. |
| 150 | |
| 151 | This value is not exported to the environment for child processes. |
| 152 | |
| 153 | #### `install-links` |
| 154 | |
| 155 | - Default: false |
| 156 | - Type: Boolean |
| 157 | |
| 158 | When set file: protocol dependencies will be packed and installed as regular dependencies instead of creating a symlink. This option has no effect on workspaces. |
| 159 | |
| 160 | ### See Also |
| 161 | |
| 162 | - [package spec](/cli/v11/using-npm/package-spec) |
| 163 | - [npm install](/cli/v11/commands/npm-install) |