-
-
Notifications
You must be signed in to change notification settings - Fork 3
Description
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-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-postinstallpackage
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.