napi-postinstall expects to require.resolve the optional dependencies of another package, but in a pnpm-style directory layout, a package can only require.resolve its own dependencies.
Details:
We are using a pnpm-style directory layout in a build sandbox that doesn't have internet access, and as part of updating Jest we run into an issue with the use of napi-postinstall in unrs-resolver.
The platform is linux-x64-gnu so we need the @unrs/resolver-binding-linux-x64-gnu package. We checked the build sandbox and see that this package is indeed installed as an optional dependency of unrs-resolver.
However, due to the pnpm-style directory-layout, it is not visible to the require.resolve in line 331 of src/index.ts.
That is, we have the following directory structure in our build sandbox:
a/node_modules/unrs-resolver contains the unrs-resolver package
a/node_modules/@unrs/resolver-binding-linux-x64-gnu is a symlink to b/node_modules/@unrs-resolver-binding-linux-x64-gnu
a/node_modules/napi-postinstall is a symlink to c/node_modules/napi-postinstall
b/node_modules/@unrs/resolver-binding-linux-x64-gnu contains the @unrs/resolver-binding-linux-x64-gnu package
c/node_modules/napi-postinstall contains the napi-postinstall package
So the optional dependency has been correctly installed into a/node_modules, but the require.resolve is in a file below c/node_nodules and cannot see it. The fallback to download the package also fails due to the missing Internet access in the build sandbox (rightly so, because we don't want to download random files during the build).
We are creating the pnpm-style directory layout with our own tooling, but it should be possible to also reproduce this with pnpm by setting hoist to false.
napi-postinstallexpects torequire.resolvethe optional dependencies of another package, but in a pnpm-style directory layout, a package can onlyrequire.resolveits own dependencies.Details:
We are using a
pnpm-style directory layout in a build sandbox that doesn't have internet access, and as part of updatingJestwe run into an issue with the use ofnapi-postinstallinunrs-resolver.The platform is
linux-x64-gnuso we need the@unrs/resolver-binding-linux-x64-gnupackage. We checked the build sandbox and see that this package is indeed installed as an optional dependency ofunrs-resolver.However, due to the
pnpm-style directory-layout, it is not visible to therequire.resolvein line 331 of src/index.ts.That is, we have the following directory structure in our build sandbox:
a/node_modules/unrs-resolvercontains theunrs-resolverpackagea/node_modules/@unrs/resolver-binding-linux-x64-gnuis a symlink tob/node_modules/@unrs-resolver-binding-linux-x64-gnua/node_modules/napi-postinstallis a symlink toc/node_modules/napi-postinstallb/node_modules/@unrs/resolver-binding-linux-x64-gnucontains the@unrs/resolver-binding-linux-x64-gnupackagec/node_modules/napi-postinstallcontains thenapi-postinstallpackageSo the optional dependency has been correctly installed into
a/node_modules, but therequire.resolveis in a file belowc/node_nodulesand cannot see it. The fallback to download the package also fails due to the missing Internet access in the build sandbox (rightly so, because we don't want to download random files during the build).We are creating the pnpm-style directory layout with our own tooling, but it should be possible to also reproduce this with
pnpmby settinghoisttofalse.