YarnPnP breaks workspace links when packages have bin files

Do you want to request a feature or report a bug?

What is the current behavior?
In yarn workspaces, if one package depends on another package with bin files (and present as a package in the workspace), the bin file is symlinked to the dependent package so it can be run. This behaviour is broken when PnP is turned on. The bin file is no longer symlinked, which is expected as it should use the PnP resolver to find them, but it doesn’t seem to be able to locate the binary.

If the current behavior is a bug, please provide the steps to reproduce.
Clone this repo: https://github.com/KwanMan/yarn-pnp-workspaces

# bootstrap
cd ./with-pnp

cd ./packages/package-a
## bin files are not symlinked as expected, as doing `yarn run [cmd]` should use the pnp resolver
ls node_modules/.bin

yarn run build ## but it doesn't resolve correctly and can't find the bin file

What is the expected behavior?
It should correctly resolve bin files of packages in the same workspace

The linked repo contains the same setup without pnp which works

# bootstrap
cd ./without-pnp

cd ./packages/package-a
## bin files from `build-script` is symlinked in so we can use them here
ls node_modules/.bin

yarn run build ## runs fine

Please mention your node.js, yarn and operating system version.

Node v10.11.0
Yarn 1.12.1
MacOS High Sierra 10.13.6

Author: Fantashit

2 thoughts on “YarnPnP breaks workspace links when packages have bin files

  1. @arcanis With latest release when I try to run babel-node I’m getting

        if (err.code !== "MODULE_NOT_FOUND") throw err;
    Error: Package "@babel/node@7.0.0" (via "/home/eagle/.cache/yarn/v4/npm-@babel-node-7.0.0-20e55bb0e015700a0f6ff281c712de7619ad56f4/node_modules/@babel/node/lib/babel-node.js") is trying to require the package "kexec" (via "kexec") without it being listed in its dependencies (@babel/polyfill, @babel/register, commander, fs-readdir-recursive, lodash, output-file-sync, v8flags, @babel/node)
        at makeError (/home/foo/app-pnp/.pnp.js:55:17)
        at Object.resolveToUnqualified (/home/foo/app-pnp/.pnp.js:1462:17)
        at Object.resolveRequest (/home/foo/app-pnp/.pnp.js:1533:31)
        at Function.Module._resolveFilename (/home/foo/app-pnp/.pnp.js:1713:30)
        at Function.Module._load (/home/foo/app-pnp/.pnp.js:1631:31)
        at Module.require (internal/modules/cjs/loader.js:643:17)
        at require (internal/modules/cjs/helpers.js:22:18)
        at /home/foo/.cache/yarn/v4/npm-@babel-node-7.0.0-20e55bb0e015700a0f6ff281c712de7619ad56f4/node_modules/@babel/node/lib/babel-node.js:94:19
        at /home/foo/.cache/yarn/v4/npm-v8flags-3.1.1-42259a1461c08397e37fe1d4f1cfb59cad85a053/node_modules/v8flags/index.js:131:14
        at /home/foo/.cache/yarn/v4/npm-v8flags-3.1.1-42259a1461c08397e37fe1d4f1cfb59cad85a053/node_modules/v8flags/index.js:39:14
    error Command failed with exit code 1.

    Also husky and nodemon are not working properly with pnp enabled.

Comments are closed.