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

Yarn PnP cache folder resolution failed on Windows #3131

Open
demigor opened this issue May 24, 2023 · 7 comments
Open

Yarn PnP cache folder resolution failed on Windows #3131

demigor opened this issue May 24, 2023 · 7 comments

Comments

@demigor
Copy link

demigor commented May 24, 2023

Hi,
I'm trying to active PnP mode for Yarn, but Esbuild (0.17.19) fails to resolve node modules. Windows OS.
Here is the log snippet, demonstrating the issue:

Checking for package alias matches
    Failed to find any package alias matches
  Read 5 entries for directory "D:\\nitro.debug\\Nitro.Web.App\\src\\blocks\\benchmarks"
  No "browser" map found in directory "D:\\nitro.debug\\Nitro.Web.App\\src\\blocks\\benchmarks"
  Searching for "react/jsx-runtime" in "node_modules" directories starting from "D:\\nitro.debug\\Nitro.Web.App\\src\\blocks\\benchmarks"
    Using Yarn PnP manifest from "D:\\nitro.debug\\Nitro.Web.App\\.pnp.cjs"
      Resolving "react/jsx-runtime" in "D:\\nitro.debug\\Nitro.Web.App\\src\\blocks\\benchmarks"
      Parsed bare identifier "react" and module path "/jsx-runtime"
      Found parent locator: ["nitro.app", "workspace:."]
      Found parent package at "./"
      Found dependency locator: ["react", "npm:18.1.0"]
      Found package "react" at "../../../C:/Users/lavni/AppData/Local/Yarn/Berry/cache/react-npm-18.1.0-d66a868dc8-8.zip/node_modules/react/"
      Resolved "react/jsx-runtime" via Yarn PnP to "D:\\C:\\Users\\lavni\\AppData\\Local\\Yarn\\Berry\\cache\\react-npm-18.1.0-d66a868dc8-8.zip\\node_modules\\react" with subpath "/jsx-runtime"
    Failed to read directory "D:\\C:\\Users\\lavni\\AppData\\Local\\Yarn\\Berry\\cache\\react-npm-18.1.0-d66a868dc8-8.zip\\node_modules\\react"
    Failed to resolve "D:\\C:\\Users\\lavni\\AppData\\Local\\Yarn\\Berry\\cache\\react-npm-18.1.0-d66a868dc8-8.zip\\node_modules\\react\\jsx-runtime" to a file

Last two lines show, that Esbuild failed to properly calculate the Yarn cache path (Failed to resolve "D:\C:\)
If I move Yarn cache to drive D:, error looks similar Failed to resolve "D:\D:\

@evanw
Copy link
Owner

evanw commented May 24, 2023

This problem is caused by Windows not supporting relative paths between drives. Yarn avoids this with a hack where they pretend that relative paths between drives are allowed, while esbuild doesn't do this. A workaround is to make sure everything in the build is on the same drive when using esbuild.

@demigor
Copy link
Author

demigor commented May 24, 2023

I moved Yarn cache to D: drive and it is still the same error. Just "D:\D:\...". Looks like path concatenation routine does not respect drive-letter rooted paths, bluntly contatenating them or so.

@evanw
Copy link
Owner

evanw commented Jun 10, 2023

Can you provide a way to reproduce the issue? Specific instructions to follow or a repository with sample code would work.

@jeiea
Copy link

jeiea commented Aug 24, 2023

I'm not sure whether this is the same with the original issue, here is my steps.

➜ Repos  yarn create vite        
➤ YN0000: · Yarn 4.0.0-rc.49
➤ YN0000: ┌ Resolution step
➤ YN0085: │ + create-vite@npm:4.4.1                                                                                                                                                                                                                                                                   
➤ YN0000: └ Completed
➤ YN0000: ┌ Fetch step
➤ YN0013: │ A package was added to the cache (+ 250.43 KiB).                                                                                                                                                                                                                                          
➤ YN0000: └ Completed
➤ YN0000: ┌ Link step
➤ YN0000: │ ESM support for PnP uses the experimental loader API and is therefore experimental
➤ YN0000: └ Completed
➤ YN0000: · Done with warnings in 0s 47ms

√ Project name: ... vite-project
√ Select a framework: » React
√ Select a variant: » TypeScript

Scaffolding project in D:\Repos\vite-project...

Done. Now run:

  cd vite-project
  yarn
  yarn dev

➜ Repos  cd .\vite-project\
➜ vite-project  yarn set version canary
➤ YN0000: Downloading https://repo.yarnpkg.com/4.0.0-rc.50/packages/yarnpkg-cli/bin/yarn.js
➤ YN0000: Saving the new release in .yarn/releases/yarn-4.0.0-rc.50.cjs
➤ YN0000: Done in 0s 596ms
➜ vite-project  yarn
➤ YN0000: · Yarn 4.0.0-rc.49
➤ YN0000: ┌ Resolution step
➤ YN0085: │ + @types/react-dom@npm:18.2.7, @types/react@npm:18.2.21, @typescript-eslint/eslint-plugin@npm:6.4.1, @typescript-eslint/parser@npm:6.4.1, @vitejs/plugin-react@npm:4.0.4, eslint-plugin-react-hooks@npm:4.6.0, eslint-plugin-react-refresh@npm:0.4.3, eslint@npm:8.47.0, and 302 more
➤ YN0000: └ Completed in 4s 325ms
➤ YN0000: ┌ Fetch step
➤ YN0013: │ 18 packages were added to the cache (+ 8.96 MiB).
➤ YN0000: └ Completed in 1s 60ms
➤ YN0000: ┌ Link step
➤ YN0000: │ ESM support for PnP uses the experimental loader API and is therefore experimental
➤ YN0007: │ esbuild@npm:0.18.20 must be built because it never has been before or the last one failed
➤ YN0000: └ Completed in 0s 735ms
➤ YN0000: · Done with warnings in 6s 156ms
➜ vite-project  yarn dev

  VITE v4.4.9  ready in 451 ms

  ➜  Local:   http://localhost:5173/
  ➜  Network: use --host to expose
  ➜  press h to show help
X [ERROR] Could not read from file: D:/Repos/vite-project/.yarn/__virtual__/react-dom-virtual-9383f81a43/7/C:/Users/jeiea/AppData/Local/Yarn/Berry/cache/react-dom-npm-18.2.0-dd675bca1c-10c0.zip/node_modules/react-dom/client.js

➜ vite-project  ✗ yarn up
➤ YN0000: · Yarn 4.0.0-rc.49
➤ YN0000: ┌ Resolution step
➤ YN0000: └ Completed
➤ YN0000: ┌ Fetch step
➤ YN0000: └ Completed
➤ YN0000: ┌ Link step
➤ YN0000: │ ESM support for PnP uses the experimental loader API and is therefore experimental
➤ YN0000: └ Completed
➤ YN0000: · Done with warnings in 0s 335ms
➜ vite-project  yarn
➤ YN0000: · Yarn 4.0.0-rc.49
➤ YN0000: ┌ Resolution step
➤ YN0000: └ Completed
➤ YN0000: ┌ Fetch step
➤ YN0000: └ Completed
➤ YN0000: ┌ Link step
➤ YN0000: │ ESM support for PnP uses the experimental loader API and is therefore experimental
➤ YN0000: └ Completed
➤ YN0000: · Done with warnings in 0s 327ms
➜ vite-project  yarn dev

  VITE v4.4.9  ready in 452 ms

  ➜  Local:   http://localhost:5173/
  ➜  Network: use --host to expose
  ➜  press h to show help
X [ERROR] Could not read from file: D:/Repos/vite-project/.yarn/__virtual__/react-dom-virtual-9383f81a43/7/C:/Users/jeiea/AppData/Local/Yarn/Berry/cache/react-dom-npm-18.2.0-dd675bca1c-10c0.zip/node_modules/react-dom/client.js

D:\Repos\vite-project\.yarn\unplugged\esbuild-npm-0.18.20-004a76d281\node_modules\esbuild\lib\main.js:1649
  let error = new Error(`${text}${summary}`);
              ^

Error: Build failed with 1 error:
error: Could not read from file: D:/Repos/vite-project/.yarn/__virtual__/react-dom-virtual-9383f81a43/7/C:/Users/jeiea/AppData/Local/Yarn/Berry/cache/react-dom-npm-18.2.0-dd675bca1c-10c0.zip/node_modules/react-dom/client.js
    at failureErrorWithLog (D:\Repos\vite-project\.yarn\unplugged\esbuild-npm-0.18.20-004a76d281\node_modules\esbuild\lib\main.js:1649:15)
    at D:\Repos\vite-project\.yarn\unplugged\esbuild-npm-0.18.20-004a76d281\node_modules\esbuild\lib\main.js:1058:25
    at D:\Repos\vite-project\.yarn\unplugged\esbuild-npm-0.18.20-004a76d281\node_modules\esbuild\lib\main.js:1525:9
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  errors: [
    {
      detail: undefined,
      id: '',
      location: null,
      notes: [],
      pluginName: '',
      text: 'Could not read from file: D:/Repos/vite-project/.yarn/__virtual__/react-dom-virtual-9383f81a43/7/C:/Users/jeiea/AppData/Local/Yarn/Berry/cache/react-dom-npm-18.2.0-dd675bca1c-10c0.zip/node_modules/react-dom/client.js'
    }
  ],
  warnings: []
}

Node.js v20.5.0
➜ vite-project  ✗

@niloo-maleki
Copy link

I had the same problem and I modified it by adding "enableGlobalCache: false" in ".yarnrc" file.
you should attention you should have type="module" in the package.json file

@demigor
Copy link
Author

demigor commented Mar 5, 2024 via email

@squidjam
Copy link

squidjam commented Jul 2, 2024

I had the same problem and I modified it by adding "enableGlobalCache: false" in ".yarnrc" file. you should attention you should have type="module" in the package.json file

You just saved me. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants