Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
1 task
Drethic opened this issue Feb 11, 2021 · 5 comments · Fixed by #2600
Closed
1 task

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

Drethic opened this issue Feb 11, 2021 · 5 comments · Fixed by #2600
Assignees
Labels
bug Something isn't working reproducible This issue can be successfully reproduced upholded Real issues without formal reproduction

Comments

@Drethic
Copy link

Drethic commented Feb 11, 2021

  • 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

@Drethic Drethic added the bug Something isn't working label Feb 11, 2021
@merceyz
Copy link
Member

merceyz commented Feb 11, 2021

You need to tell the top most .pnp.js file (/Projects/demo/.pnp.js in your error) to not control that folder using pnpIgnorePatterns

@Drethic
Copy link
Author

Drethic commented Feb 11, 2021

I've updated the root .yarnrc.yaml to look like this:

yarnPath: .yarn/releases/yarn-2.4.0.cjs
pnpIgnorePatterns:
  - "./lib/.*"

No change in the error caused. Is there a different way I need to format the pattern?

@merceyz
Copy link
Member

merceyz commented 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

@merceyz merceyz added reproducible This issue can be successfully reproduced upholded Real issues without formal reproduction labels Feb 11, 2021
@merceyz merceyz self-assigned this Feb 11, 2021
@Drethic
Copy link
Author

Drethic commented Feb 11, 2021

Thank you merceyz, the updated pattern worked and I can run the scripts in the child.

@Dwiga
Copy link

Dwiga commented 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working reproducible This issue can be successfully reproduced upholded Real issues without formal reproduction
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants