evanw / esbuild

An extremely fast bundler for the web
https://esbuild.github.io/
MIT License
37.95k stars 1.14k forks source link

Yarn PnP activating when project has nodeLinker: node-modules #3876

Open MaxLap opened 1 month ago

MaxLap commented 1 month ago

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 commented 1 month ago

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

merceyz commented 1 month ago

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.