vitejs / vite

Next generation frontend tooling. It's fast!
http://vite.dev
MIT License
68.79k stars 6.21k forks source link

preserveSymlinks option not being sent to esbuild, breaking some execution environments (such as when run from/with junction'd folders on Windows) [fix] #16197

Open mnmkay opened 8 months ago

mnmkay commented 8 months ago

Describe the bug

I've run into this when attempting to run SvelteKit's introductory "SvelteKit demo app" from a folder that is junction'd (symlinked) on Windows. After a failing application (described in Steps to Reproduce below), I took a look around the vite code and was able to get it working. Whether or not the best resolution, this seems most closely related to vitejs/vite, nonetheless.

For my specific situation, these two locations require preserveSyminks to be set to true (as it is currently, the code is hardcoded to fail): https://github.com/vitejs/vite/blob/72104f6de5398a1a0511404e8485b3b7721be537/packages/vite/src/node/config.ts#L1100 https://github.com/vitejs/vite/blob/72104f6de5398a1a0511404e8485b3b7721be537/packages/vite/src/node/config.ts#L1063

Line 1100 goes to the externalize-deps plugin (via tryNodeResolve) and At line 1063, above it needs to be among the options, which get fed into esbuild (flagsForBuildOptions):

https://github.com/evanw/esbuild/blob/9d1777f23d9b64c186345223d92f319e59388d8b/lib/shared/common.ts#L225

(Incidentally and importantly, for eventual configuration/fix purposes: it seems these code locations are hit before either svelte.config.js or vite.config.ts are ever read)

Seems like this would not affect only Windows, but I don't know: Some other issues that might be related: (no idea). #16176 #10802

Reproduction

https://kit.svelte.dev/

Steps to reproduce

#run from a junction'd windows directory (ie example, CWD is folder C:\project that is a junction pointing to D:\real_project):
npm create svelte@latest my-app
cd my-app
npm install
npm run dev -- --open
...

#choose SvelteKit demo app, be navigated to the opened localhost url, then get to a broken application page with the console error:

The request url "D:/real_project/my-app/node_modules/@sveltejs/kit/src/runtime/client/entry.js" is outside of Vite serving allow list.
# to work the PATH needs to start with C:/project, remaining unresolved

System Info

System:
    OS: Windows 10 10.0.19045
    ...
  Binaries:
    Node: 20.10.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.22 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 10.2.3 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Chromium (122.0.2365.80)
    Internet Explorer: 11.0.19041.3636
  npmPackages:
    vite: ^5.0.3 => 5.1.6

Used Package Manager

npm

Logs

No response

Validations

bmcbarron commented 8 months ago

This started happening to me after a node_modules reinstall this week. It seems like maybe some sveltejs files aren't being whitelisted anymore. My workaround was to update server.fs.allow in vite.config.ts:

  allow = [..., '<path to node_modules>/@sveltejs/kit/src/runtime']

Edit: My build environment is git bash on Windows.