Skip to content

This notebook belongs to

Sadat Jubayer

Senior Software Engineer at Premio

If found, please return to hello@jubayer.dev

Vol. 7Seven years of building

Started
January 2020
Everyday tools
TypeScript, Vue, React, Next.js, NestJS, React Native
Education
B.Sc. CSSE, AIUB, 2020
2 min readDev Tool

Handle pnpm 10 blocked postinstall scripts

Review a skipped dependency build, allow that package with onlyBuiltDependencies and rebuild it under pnpm 10.

You install a project with pnpm 10. The package is in node_modules, but a tool that depends on its build step cannot find the generated file. Check whether pnpm skipped the dependency's install script before reinstalling the package.

Check what pnpm skipped

pnpm 10 changed the default for dependency lifecycle scripts. A registry dependency can be present on disk while its build or postinstall step remains blocked. The install output can list ignored build scripts. Start with the name in that output and find out what its script does.

To reproduce the warning, create a scratch project and save this as builder/package.json. The postinstall writes built.txt inside the installed package.

{
  "name": "report-builder",
  "version": "1.0.0",
  "scripts": {
    "postinstall": "node -e \"require('node:fs').writeFileSync('built.txt', 'ready')\""
  }
}

Save this as package.json at the project root.

{
  "private": true,
  "dependencies": {
    "report-builder": "file:./report-builder-1.0.0.tgz"
  }
}

Pack the dependency and run the install from that root with pnpm 10.

npm pack ./builder
pnpm install

With the default policy, the ignored-build warning names report-builder and node_modules/report-builder/built.txt is missing.

Allow one dependency to build

Review the dependency's lifecycle script and the version your lockfile resolves. If the build belongs there, add the package name to onlyBuiltDependencies in the root pnpm-workspace.yaml. Keep any names you already reviewed.

onlyBuiltDependencies:
  - report-builder

This grants build permission to report-builder on installs that use the checked-in workspace policy.

If your workspace already uses allowBuilds (available since pnpm 10.26), put report-builder: true under that key.

diagram

One package, two build outcomes

Both installs can place report-builder on disk, but only the allowed build produces its generated file.

Rebuild that dependency in your working copy after changing the policy.

pnpm rebuild report-builder

The rebuild logs the package's postinstall, and built.txt appears under node_modules/report-builder.

Commit the workspace policy and check a clean install before handing the change to CI. A workspace may contain other packages that share this policy, so grant only the one whose build you reviewed. A name-only entry covers future versions with that name. Review lockfile updates for approved dependencies when their versions change.

If the file is still missing and the postinstall ran, start with its first build error.