Fixing Bun’s “Blocked postinstall” for Dependencies
If bun install ends with "Blocked 1 postinstall." and a dependency's postinstall never runs, Bun is blocking scripts from packages that are not on its allowlist. Either list the package name in trustedDependencies in package.json, or run bun pm trust, and the script will run.
This is the fix for when you switched from npm to Bun and something that used to run at install time, such as a native addon build or a binary download, no longer runs. Adding trustedDependencies replaces Bun's default allowlist, and packages that used to work can stop, so I checked that with real output too.
The test environment was Ubuntu 24.04 (x86_64), Bun 1.4.4, and Node.js 22.23.4. Packages were fetched from registry.npmjs.org. I did not test projects that use workspaces, dependencies via git: or github:, bun install --frozen-lockfile and bun ci, or Windows and macOS. For the official documentation, I checked the source files at the tag used in the test (bun-v1.4.4) on GitHub, and the links point there.
Why Bun blocks dependency scripts
An npm package can put preinstall, install, postinstall, and similar commands in the scripts field of its package.json, and npm runs them during installation. Since any command can be written there, a malicious package can run code on your machine just by being installed.
According to the official lifecycle scripts documentation, Bun avoids this by running scripts only for packages on an allowlist. If package.json has no trustedDependencies, the allowlist is a default list of widely used packages. If you write trustedDependencies, only the packages you list are allowed (I check this in a later section). You can see the default list with bun pm default-trusted. In the test environment, Bun 1.4.4 had 367 entries.
$ bun pm default-trusted | head -1
Default trusted dependencies (367):
The default list applies only to packages installed from the npm registry. Packages installed with file:, link:, or git: do not run their scripts unless they are listed in trustedDependencies, even if their name is on the default list (note in the official documentation).
Confirming the block
I tested a project with these three dependencies:
core-js: an npm package with a postinstall. It is not on the default list.utf-8-validate: an npm package with an install script (node-gyp-build). It is on the default list.my-addon: a local package installed withfile:. To show that its scripts ran, each of preinstall, install, and postinstall appends one line totrace.txtin the project.
The project's own package.json also has a postinstall that appends one line to trace.txt.
{
"name": "trust-demo",
"version": "1.0.0",
"scripts": {
"postinstall": "node -e \"require('fs').appendFileSync('trace.txt', 'root postinstall\\n')\""
},
"dependencies": {
"core-js": "3.45.1",
"utf-8-validate": "6.0.5",
"my-addon": "file:./my-addon"
}
}
The package.json of my-addon is as follows.
{
"name": "my-addon",
"version": "1.0.0",
"scripts": {
"preinstall": "node -e \"require('fs').appendFileSync(process.env.INIT_CWD + '/trace.txt', 'my-addon preinstall\\n')\"",
"install": "node -e \"require('fs').appendFileSync(process.env.INIT_CWD + '/trace.txt', 'my-addon install\\n')\"",
"postinstall": "node -e \"require('fs').appendFileSync(process.env.INIT_CWD + '/trace.txt', 'my-addon postinstall\\n')\""
}
}
This is the result of running bun install without trustedDependencies.
$ bun install
bun install v1.4.4 (38afee6c8)
Resolving dependencies
Resolved, downloaded and extracted [12]
Saved lockfile
$ node -e "require('fs').appendFileSync('trace.txt', 'root postinstall\n')"
+ core-js@3.45.1 (v3.51.0 available)
+ my-addon@my-addon
+ utf-8-validate@6.0.5 (v6.0.6 available)
4 packages installed [255.00ms]
Blocked 4 postinstalls. Run `bun pm untrusted` for details.
$ cat trace.txt
root postinstall
trace.txt contains only the line from the project's own postinstall. The project's own script runs, and only the dependencies' scripts are blocked (official bun install documentation).
The 4 in "Blocked 4 postinstalls" is the count of core-js's postinstall plus my-addon's preinstall, install, and postinstall. Although the message says "postinstalls," preinstall and install were blocked too.
You can see which scripts were blocked, and for which package, with bun pm untrusted.
$ bun pm untrusted
bun pm untrusted v1.4.4 (38afee6c8)
./node_modules/core-js @3.45.1
» [postinstall]: node -e "try{require('./postinstall')}catch(e){}"
./node_modules/my-addon @my-addon
» [preinstall]: node -e "require('fs').appendFileSync(process.env.INIT_CWD + '/trace.txt', 'my-addon preinstall\n')"
» [install]: node -e "require('fs').appendFileSync(process.env.INIT_CWD + '/trace.txt', 'my-addon install\n')"
» [postinstall]: node -e "require('fs').appendFileSync(process.env.INIT_CWD + '/trace.txt', 'my-addon postinstall\n')"
These dependencies had their lifecycle scripts blocked during install.
If you trust them and wish to run their scripts, use `bun pm trust`.
utf-8-validate, which is on the default list, does not appear here. I removed node_modules and reinstalled with bun install --verbose, then extracted only the script-related lines. The scripts of utf-8-validate did run.
$ rm -rf node_modules trace.txt && bun install --verbose 2>&1 | grep -E '^\[Scripts\]|^Blocked'
Blocked 1 scripts for: core-js@3.45.1
Blocked 3 scripts for: my-addon@my-addon
[Scripts] Starting scripts for "utf-8-validate"
[Scripts] Finished scripts for "utf-8-validate"
[Scripts] Starting scripts for "trust-demo"
[Scripts] Finished scripts for "trust-demo"
Blocked 4 postinstalls. Run `bun pm untrusted` for details.
Allowing them in trustedDependencies
List the names of the packages you want to run in the trustedDependencies array in package.json.
"trustedDependencies": [
"core-js",
"my-addon"
]
After adding this, I ran bun install without removing node_modules, and the scripts of the two allowed packages ran. I deleted trace.txt first so the results would not mix with the earlier run.
$ rm -f trace.txt
$ bun install --verbose 2>&1 | grep -E '^\[Scripts\]|^Blocked'
[Scripts] Starting scripts for "my-addon"
[Scripts] Starting scripts for "core-js"
[Scripts] Finished scripts for "core-js"
[Scripts] Finished scripts for "my-addon"
[Scripts] Starting scripts for "trust-demo"
[Scripts] Finished scripts for "trust-demo"
$ cat trace.txt
my-addon preinstall
my-addon install
my-addon postinstall
root postinstall
The scripts of my-addon ran in the order preinstall, install, postinstall, followed by the project's own postinstall.
The allowed package names were also written to the lockfile, bun.lock. The official lifecycle scripts documentation also says Bun reads trustedDependencies to run scripts and records the names in the lockfile.
$ grep -A3 trustedDependencies bun.lock
"trustedDependencies": [
"core-js",
"my-addon",
],
Allowing them with bun pm trust
Instead of editing package.json by hand, you can allow packages with bun pm trust <package-name>. This command runs the blocked scripts right away and adds the names to trustedDependencies in package.json (official bun pm documentation).
$ bun pm trust core-js my-addon
bun pm trust v1.4.4 (38afee6c8)
./node_modules/core-js @3.45.1
✓ [postinstall]: node -e "try{require('./postinstall')}catch(e){}"
./node_modules/my-addon @my-addon
✓ [preinstall]: node -e "require('fs').appendFileSync(process.env.INIT_CWD + '/trace.txt', 'my-addon preinstall\n')"
✓ [install]: node -e "require('fs').appendFileSync(process.env.INIT_CWD + '/trace.txt', 'my-addon install\n')"
✓ [postinstall]: node -e "require('fs').appendFileSync(process.env.INIT_CWD + '/trace.txt', 'my-addon postinstall\n')"
4 scripts ran across 2 packages [96.00ms]
After running it, package.json contained "trustedDependencies": ["core-js", "my-addon"], the same as when I wrote it by hand. There is also --all, which allows everything that was blocked, and --dry-run, which shows what would run without running it.
For a package you are about to add, bun add --trust adds it to the dependencies and also adds its name to trustedDependencies in the same step.
$ bun add --trust core-js@3.45.1
bun add v1.4.4 (38afee6c8)
Saved lockfile
installed core-js@3.45.1
1 package installed [48.00ms]
$ cat package.json
{
"name": "add-demo",
"version": "1.0.0",
"dependencies": {
"core-js": "3.45.1"
},
"trustedDependencies": [
"core-js"
]
}
Writing trustedDependencies drops the default list
Be aware that once you write trustedDependencies, the default list stops being used. The official explanation of how trustedDependencies behaves says that trustedDependencies replaces the default list rather than being added to it.
After I allowed core-js and my-addon with bun pm trust, I removed node_modules and reinstalled. The utf-8-validate script, which had been running before, was now blocked.
$ rm -rf node_modules trace.txt && bun install
bun install v1.4.4 (38afee6c8)
$ node -e "require('fs').appendFileSync('trace.txt', 'root postinstall\n')"
+ core-js@3.45.1
+ my-addon@my-addon
+ utf-8-validate@6.0.5
4 packages installed [131.00ms]
Blocked 1 postinstall. Run `bun pm untrusted` for details.
$ bun pm untrusted
bun pm untrusted v1.4.4 (38afee6c8)
./node_modules/utf-8-validate @6.0.5
» [install]: node-gyp-build
These dependencies had their lifecycle scripts blocked during install.
If you trust them and wish to run their scripts, use `bun pm trust`.
Running bun pm trust did not add the default-list packages to trustedDependencies. While the node_modules left by the earlier install was still there, running bun install printed no "Blocked" line. The block appears when you delete node_modules and reinstall. However, bun pm untrusted listed utf-8-validate even before I removed node_modules (I checked this when I wrote the list by hand).
You can check which packages are currently allowed with bun pm ls --trusted. Once trustedDependencies is written, only the packages listed there appear (I replaced the working directory path in the output with /path/to/app).
$ bun pm ls --trusted
/path/to/app node_modules (4 installed)
├── core-js@3.45.1
└── my-addon@my-addon
To fix this, add to trustedDependencies any package from the default list whose scripts you want to run.
"trustedDependencies": [
"core-js",
"my-addon",
"utf-8-validate"
]
With this package.json, installing from a state without node_modules ran all three packages' scripts, and nothing was blocked.
$ rm -rf node_modules trace.txt && bun install --verbose 2>&1 | grep -E '^\[Scripts\]|^Blocked'
[Scripts] Starting scripts for "utf-8-validate"
[Scripts] Starting scripts for "my-addon"
[Scripts] Starting scripts for "core-js"
[Scripts] Finished scripts for "core-js"
[Scripts] Finished scripts for "utf-8-validate"
[Scripts] Finished scripts for "my-addon"
[Scripts] Starting scripts for "trust-demo"
[Scripts] Finished scripts for "trust-demo"
$ bun pm untrusted
bun pm untrusted v1.4.4 (38afee6c8)
Found 0 untrusted dependencies with scripts.
This means all packages with scripts are in "trustedDependencies" or none of your dependencies have scripts.
For more information, visit https://bun.com/docs/install/lifecycle#trusteddependencies
After writing trustedDependencies, run bun pm untrusted and check that it shows nothing. That way you notice packages that dropped off the default list.
Blocking all dependency scripts
To block every dependency script, set trustedDependencies to an empty array. All packages were blocked, including those on the default list.
$ bun install
bun install v1.4.4 (38afee6c8)
Saved lockfile
$ node -e "require('fs').appendFileSync('trace.txt', 'root postinstall\n')"
+ core-js@3.45.1 (v3.51.0 available)
+ my-addon@my-addon
+ utf-8-validate@6.0.5 (v6.0.6 available)
4 packages installed [51.00ms]
Blocked 5 postinstalls. Run `bun pm untrusted` for details.
$ cat trace.txt
root postinstall
Even with an empty array, the project's own postinstall still runs. To also stop the project's own scripts, use bun install --ignore-scripts. I tried it with a package.json that listed all three packages in trustedDependencies. trace.txt was not created, so neither the scripts of the allowed my-addon nor the project's own postinstall ran.
$ bun install --ignore-scripts
bun install v1.4.4 (38afee6c8)
Saved lockfile
+ core-js@3.45.1 (v3.51.0 available)
+ my-addon@my-addon
+ utf-8-validate@6.0.5 (v6.0.6 available)
4 packages installed [27.00ms]
$ cat trace.txt
cat: trace.txt: No such file or directory
Instead of passing the flag every time, you can set ignoreScripts = true under [install] in bunfig.toml, or ignore-scripts=true in .npmrc. Both are described in the official documentation for –ignore-scripts.




