esbuild icon indicating copy to clipboard operation
esbuild copied to clipboard

Yarn PnP activating when project has nodeLinker: node-modules

Open MaxLap opened this issue 1 year ago • 2 comments

It seems that if my home folder contains a .pnp.cjs file, esbuild uses PnP even if the project itself is configured with nodeLinker: node-modules in its .yarnrc.yml.

I'm not sure if the problem is on esbuild or on Yarn.

I'm on WSL2 with Ubuntu 24.04, with esbuild 0.23.0, yarn 4.3.0. I just did a fresh install. Installed nvm, then node 20, then corepack enable. My project was already setup for node-modules mode with its .yarnrc.yml.

Every package would be unresolvable within esbuild. Using verbose logging, I got this kind of output for each import:

● [DEBUG] Resolving import "tailwindcss-stimulus-components" in directory "/home/max/projects/documold/app/javascript/controllers" of type "import-statement"

  Checking for package alias matches
    Failed to find any package alias matches
  Read 26 entries for directory "/home/max/projects/documold/app/javascript/controllers"
  No "browser" map found in directory "/home/max/projects/documold/app/javascript/controllers"
  Searching for "tailwindcss-stimulus-components" in "node_modules" directories starting from "/home/max/projects/documold/app/javascript/controllers"
    Using Yarn PnP manifest from "/home/max/.pnp.cjs"
      Resolving "tailwindcss-stimulus-components" in "/home/max/projects/documold/app/javascript/controllers"
      Parsed bare identifier "tailwindcss-stimulus-components" and module path ""
      Found parent locator: ["max", "workspace:."]
      Found parent package at "./"
      Failed to find "tailwindcss-stimulus-components" in "packageDependencies" of parent package
      Searching for a fallback because "enableTopLevelFallback" is true
        Stopping because ["max", "workspace:."] is in "fallbackExclusionList"
    The Yarn PnP path resolution algorithm returned an error

If I rename the .pnp.cjs file from my home dir, then things work and pnp is not used.

My understanding is that nodeLinker: node-modules in the project's .yarnrc.yml should turn pnp off for that project. But it clearly doesn't (at least for esbuild). Am I doing something wrong? I'm just hoping to save someone else's time since the logs without verbose are not helpful for this issue.

Thanks

MaxLap avatar Aug 13 '24 12:08 MaxLap

I'm not sure it's normal for there to be a .pnp.cjs file in the home dir. I may have accidentally initiated a project in my home dir. No idea how that happened, but I also had a .git directory there...

After a 2nd fresh install, I did not get a "random" .pnp.cjs in my home dir, and things worked fine. So maybe then it looked like nested project which I don't know the expected behavior of, but doesn't concern me. Feel free to close. Sorry for the trouble

MaxLap avatar Aug 13 '24 13:08 MaxLap

Duplicate of https://github.com/evanw/esbuild/issues/2647

I may have accidentally initiated a project in my home dir

That's the most likely explanation, Yarn shouldn't write it to the home directory unless you run an install there.

merceyz avatar Aug 14 '24 08:08 merceyz

Closing as by design, just like #2647.

evanw avatar Sep 22 '24 01:09 evanw