question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Bug] Yarn 2.4.0 reading parent .pnp.js for pnpApi when enableGlobalCache is false

See original GitHub issue
  • I’d be willing to implement a fix

Describe the bug

I upgraded from Yarn 2.3.3 to 2.4.0 and am unable to run a yarn script in a child directory. I have the following folder structure:

package.json
yarn.lock
.yarn/releases/yarn-2.4.0.cjs
.yarnrc.yml
/lib/package.json
/lib/yarn.lock

As part of my root package I have pnpify installed so I can use eslint across all sub projects.

When you install the root, then enabled pnpify, then install lib, and then run any yarn command from the lib scripts you get the following error:

Internal Error: Unable to locate pnpapi, the module '/Projects/demo/lib/.pnp.js' is controlled by multiple pnpapi instances.
This is usually caused by using the global cache (enableGlobalCache: true)

Controlled by:
  /Projects/demo/lib/.pnp.js
  /Projects/demo/.pnp.js
This is usually caused by using the global cache (enableGlobalCache: true)

Controlled by:
  /Projects/demo/lib/.pnp.js
  /Projects/demo/.pnp.js
    at Object.findApiPathFor (/Projects/demo/lib/.pnp.js:29343:13)
    at Function.external_module_.Module._resolveFilename (/Projects/demo/lib/.pnp.js:28315:182)
    at Function.external_module_.Module._load (/Projects/demo/lib/.pnp.js:28204:48)
    at Module.require (internal/modules/cjs/loader.js:903:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at S (/Projects/demo/.yarn/releases/yarn-2.4.0.cjs:2:418340)
    at Module.k (/Projects/demo/.yarn/releases/yarn-2.4.0.cjs:2:418445)
    at S.findPackageLocation (/Projects/demo/.yarn/releases/yarn-2.4.0.cjs:2:265281)
    at /Projects/demo/.yarn/releases/yarn-2.4.0.cjs:2:425060
    at Function.openPromise (/Projects/demo/.yarn/releases/yarn-2.4.0.cjs:2:489248)

To Reproduce

I’ve created a demo repo to reproduce the issue here. These are the steps to setup the demo and what to expect:

Setup Steps

  1. Run yarn install in the root directory
  2. Run yarn pnpify --sdk vscode to install the sdks
  3. Run yarn install in the lib directory
  4. Run yarn dev in the lib directory

You should receive the following error message when you run yarn dev:

Internal Error: Unable to locate pnpapi, the module '/Projects/demo/lib/.pnp.js' is controlled by multiple pnpapi instances.
This is usually caused by using the global cache (enableGlobalCache: true)

Controlled by:
  /Projects/demo/lib/.pnp.js
  /Projects/demo/.pnp.js
This is usually caused by using the global cache (enableGlobalCache: true)

Controlled by:
  /Projects/demo/lib/.pnp.js
  /Projects/demo/.pnp.js
    at Object.findApiPathFor (/Projects/demo/lib/.pnp.js:29343:13)
    at Function.external_module_.Module._resolveFilename (/Projects/demo/lib/.pnp.js:28315:182)
    at Function.external_module_.Module._load (/Projects/demo/lib/.pnp.js:28204:48)
    at Module.require (internal/modules/cjs/loader.js:903:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at S (/Projects/demo/.yarn/releases/yarn-2.4.0.cjs:2:418340)
    at Module.k (/Projects/demo/.yarn/releases/yarn-2.4.0.cjs:2:418445)
    at S.findPackageLocation (/Projects/demo/.yarn/releases/yarn-2.4.0.cjs:2:265281)
    at /Projects/demo/.yarn/releases/yarn-2.4.0.cjs:2:425060
    at Function.openPromise (/Projects/demo/.yarn/releases/yarn-2.4.0.cjs:2:489248)

Screenshots

N/A

Environment if relevant (please complete the following information):

  • OS: Mac OS 11.1
  • Node version 12.19.0
  • Yarn version 2.4.0

Additional context

None

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
merceyzcommented, Feb 11, 2021

Seems to be a bug here on our end, you can work around it by getting more specific with the pattern

pnpIgnorePatterns:
  - "./lib/.*"
  - "./lib/**"

Make sure to run an install after modifying .yarnrc.yml

0reactions
Dwigacommented, Nov 19, 2021

Hi, I am facing this error please help me, it’s a bit different and I can’t fix it by myself… I just updated my yarn version to version 2.4.3 from version 1.x

and I got this error

Controlled by:                                                                                                                                   │
│   /home/dwi/labs/dwilab/node/booklette-app/.pnp.js                                                                                              │
│   /home/dwi/.pnp.js
Read more comments on GitHub >

github_iconTop Results From Across the Web

Error: Unable to locate pnpapi ... is controlled by multiple ...
Run a project with Yarn 2 pnp; Have some incorrect globalCache settings? ... listed in external dependencies and in Settings > Javascript >...
Read more >
Plug'n'Play | Yarn - Package Manager
An overview of Plug'n'Play, a powerful and innovative installation strategy for Node.
Read more >
Repository - GitLab
Yarn supports zero-installs, which means that as long as you store your cache and your .pnp.js file inside your repository, everything will ...
Read more >
Taxonomy - PnP/PnPjs
The side affect of this is that the parent is no longer chainable, meaning you need to load a new term instance to...
Read more >
Plug'n'Play | Yarn - JavaScript 软件包管理器
If the answer to any of these questions is yes, make sure to visit the PnP API page after reading the introduction! Unveiled...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found