storybookjs/storybook

[Bug]: "Failed to load static files" error with Yarn PnP with global cache on windows

blikblum opened this issue · 5 comments

Describe the bug

A minimal storybook setup fails to run on windows with the following callstack:

Error: Failed to load static files, no such directory: .\C:\Users\camar\AppData\Local\Yarn\Berry\cache\@storybook-manager-npm-7.5.1-b9f503fb19-10c0.zip\node_modules\@storybook\manager\static
Make sure this directory exists, or omit the -s (--static-dir) option.
    at parseStaticDir (C:\Users\camar\AppData\Local\Yarn\Berry\cache\@storybook-core-server-npm-7.5.1-02b6f24941-10c0.zip\node_modules\@storybook\core-server\dist\presets\common-preset.js:14:2310)
    at async C:\Users\camar\AppData\Local\Yarn\Berry\cache\@storybook-core-server-npm-7.5.1-02b6f24941-10c0.zip\node_modules\@storybook\core-server\dist\presets\common-preset.js:17:2925
    at async Promise.all (index 0)
    at async Object.favicon (C:\Users\camar\AppData\Local\Yarn\Berry\cache\@storybook-core-server-npm-7.5.1-02b6f24941-10c0.zip\node_modules\@storybook\core-server\dist\presets\common-preset.js:17:2687)
    at async useStatics (C:\Users\camar\AppData\Local\Yarn\Berry\cache\@storybook-core-server-npm-7.5.1-02b6f24941-10c0.zip\node_modules\@storybook\core-server\dist\index.js:48:6508)
    at async Promise.all (index 2)
    at async storybookDevServer (C:\Users\camar\AppData\Local\Yarn\Berry\cache\@storybook-core-server-npm-7.5.1-02b6f24941-10c0.zip\node_modules\@storybook\core-server\dist\index.js:104:1159)
    at async buildDevStandalone (C:\Users\camar\AppData\Local\Yarn\Berry\cache\@storybook-core-server-npm-7.5.1-02b6f24941-10c0.zip\node_modules\@storybook\core-server\dist\index.js:119:3007)
    at async withTelemetry (C:\Users\camar\AppData\Local\Yarn\Berry\cache\@storybook-core-server-npm-7.5.1-02b6f24941-10c0.zip\node_modules\@storybook\core-server\dist\index.js:103:3903)
    at async dev (C:\Users\camar\AppData\Local\Yarn\Berry\cache\@storybook-cli-npm-7.5.1-8d005d3abc-10c0.zip\node_modules\@storybook\cli\dist\generate.js:473:401)

On linux, works fine

The path ".\C:\Users\camar\AppData\Local\Yarn\Berry\cache@storybook-manager-npm-7.5.1-b9f503fb19-10c0.zip\node_modules@storybook\manager\static" is almost correct except for the ".\" prefix

Somehow parseStaticDir is adding '.\' prefix when should not

To Reproduce

https://github.com/blikblum/yarn-storybook

System

Storybook Environment Info:

  System:
    OS: Windows 10 10.0.19045
    CPU: (8) x64 Intel(R) Core(TM) i7-7700 CPU @ 3.60GHz
  Binaries:
    Node: 18.12.1 - C:\Program Files\nodejs\node.EXE
    Yarn: 4.0.0 - ~\AppData\Roaming\npm\yarn.CMD <----- active
    npm: 8.10.0 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.19041.3570.0), Chromium (116.0.1938.81)

Additional context

No response

I think I have fixed this one in 7.6.0-alpha.3. Can you try it out?

Thanks . This fixes this error. Although still not working.

Now fails with a different error:

X [ERROR] Could not read from file: D:/repositories/storybook-yarn/.yarn/__virtual__/react-dom-virtual-5c8c782fcf/4/C:/Users/camar/AppData/Local/Yarn/Berry/cache/react-dom-npm-18.2.0-dd675bca1c-10c0.zip/node_modules/react-dom/index.js

X [ERROR] Could not read from file: D:/repositories/storybook-yarn/.yarn/__virtual__/@storybook-addon-essentials-virtual-db46dc48fe/4/C:/Users/camar/AppData/Local/Yarn/Berry/cache/@storybook-addon-essentials-npm-7.6.0-alpha.3-bbfebc8cc7-10c0.zip/node_modules/@storybook/addon-essentials/dist/docs/mdx-react-shim.mjs

X [ERROR] Could not read from file: D:/repositories/storybook-yarn/.yarn/__virtual__/react-dom-virtual-5c8c782fcf/4/C:/Users/camar/AppData/Local/Yarn/Berry/cache/react-dom-npm-18.2.0-dd675bca1c-10c0.zip/node_modules/react-dom/client.js

C:\Users\camar\AppData\Local\Yarn\Berry\cache\@storybook-cli-npm-7.6.0-alpha.3-17672de923-10c0.zip\node_modules\@storybook\cli\bin\index.js:23
  throw error;
  ^

Error: Build failed with 3 errors:
error: Could not read from file: D:/repositories/storybook-yarn/.yarn/__virtual__/react-dom-virtual-5c8c782fcf/4/C:/Users/camar/AppData/Local/Yarn/Berry/cache/react-dom-npm-18.2.0-dd675bca1c-10c0.zip/node_modules/react-dom/index.js
error: Could not read from file: D:/repositories/storybook-yarn/.yarn/__virtual__/@storybook-addon-essentials-virtual-db46dc48fe/4/C:/Users/camar/AppData/Local/Yarn/Berry/cache/@storybook-addon-essentials-npm-7.6.0-alpha.3-bbfebc8cc7-10c0.zip/node_modules/@storybook/addon-essentials/dist/docs/mdx-react-shim.mjs
error: Could not read from file: D:/repositories/storybook-yarn/.yarn/__virtual__/react-dom-virtual-5c8c782fcf/4/C:/Users/camar/AppData/Local/Yarn/Berry/cache/react-dom-npm-18.2.0-dd675bca1c-10c0.zip/node_modules/react-dom/client.js
    at failureErrorWithLog (D:\repositories\storybook-yarn\.yarn\unplugged\esbuild-npm-0.18.20-004a76d281\node_modules\esbuild\lib\main.js:1649:15)
    at D:\repositories\storybook-yarn\.yarn\unplugged\esbuild-npm-0.18.20-004a76d281\node_modules\esbuild\lib\main.js:1058:25
    at D:\repositories\storybook-yarn\.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:/repositories/storybook-yarn/.yarn/__virtual__/react-dom-virtual-5c8c782fcf/4/C:/Users/camar/AppData/Local/Yarn/Berry/cache/react-dom-npm-18.2.0-dd675bca1c-10c0.zip/node_modules/react-dom/index.js'
    },
    {
      detail: undefined,
      id: '',
      location: null,
      notes: [],
      pluginName: '',
      text: 'Could not read from file: D:/repositories/storybook-yarn/.yarn/__virtual__/@storybook-addon-essentials-virtual-db46dc48fe/4/C:/Users/camar/AppData/Local/Yarn/Berry/cache/@storybook-addon-essentials-npm-7.6.0-alpha.3-bbfebc8cc7-10c0.zip/node_modules/@storybook/addon-essentials/dist/docs/mdx-react-shim.mjs'
    },
    {
      detail: undefined,
      id: '',
      location: null,
      notes: [],
      pluginName: '',
      text: 'Could not read from file: D:/repositories/storybook-yarn/.yarn/__virtual__/react-dom-virtual-5c8c782fcf/4/C:/Users/camar/AppData/Local/Yarn/Berry/cache/react-dom-npm-18.2.0-dd675bca1c-10c0.zip/node_modules/react-dom/client.js'
    }
  ],
  warnings: []
}

Node.js v18.12.1

Tried 7.6.0-alpha.6, but same issues as above with enableGlobalCache: true . There is a issue with resolving different drive paths. See discussion evanw/esbuild#3131 (comment)

I managed to workaround it by configuring to same drive: globalFolder: "D:/.yarn/berry/global"

Ran into the same problem on a completely unrelated project (building a Tauri app), but following @psychobolt's configuration change solved the issue for me as well.

So, potentially unrelated to Storybook specifically and something around Yarn PnP + Windows.

@tbrockman From, evanw/esbuild#3131 (comment)

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.

Yarn should be able to resolve different drives without issues. Esbuild does not. So any libraries that depend on Esbuild will have the same issue, as I experienced similarly with Stylelint...

For another workaround is to configure environment variables, but you'll have to require all Window users to have HOME defined... e.g.

# .env for windows
HOME="D:/"
injectEnvironmentFiles:
  - .env?

globalFolder: "${HOME}/.yarn/berry/global"