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

Vite failed with projects involving cross drive links on Windows #10802

Open
7 tasks done
lihe07 opened this issue Nov 6, 2022 · 11 comments
Open
7 tasks done

Vite failed with projects involving cross drive links on Windows #10802

lihe07 opened this issue Nov 6, 2022 · 11 comments

Comments

@lihe07
Copy link

lihe07 commented Nov 6, 2022

Describe the bug

For some reasons, I have my users dir (C:\Users) linked to another dir (D:\Users) on another disk.
When I start the dev server of a project at C:\Users\lihe07\Desktop\solidjs-template, vite is not working properly and some errors pops out at the console:
img1

However, the dev server started at D:\Users\lihe07\Desktop\solidjs-template can work properly, and give the expected output:

img2

I have also tried a vue project and the result is similar.

It also fails when I tried to build the project npm run build and the log can be found below.

Reproduction

https://github.com/lihe07/solidjs-template

Steps to reproduce

Actually almost every vite projects in this condition can reproduce the issue:

  1. Make a soft link of the project / the parent dir of the project
    mklink /J DEST SRC
  2. cd, and do npm i
  3. run npm run dev or npm run build and the issue will emerge

System Info

System:
    OS: Windows 10 10.0.19045
    CPU: (8) x64 Intel(R) Xeon(R) CPU E3-1241 v3 @ 3.50GHz
    Memory: 7.34 GB / 15.96 GB
  Binaries:
    Node: 19.0.1 - C:\Program Files\nodejs\node.EXE
    npm: 8.19.2 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (21.1.0), Chromium (21.1.0), ChromiumDev (21.1.0)
    Internet Explorer: 11.0.19041.1566
  npmPackages:
    vite: ^3.2.2 => 3.2.2

Used Package Manager

npm

Logs

Logs

[email protected] build
vite build --debug

vite:config bundled config file loaded in 588.18ms +0ms
vite:esbuild init tsconfck (root: C:/Users/lihe07/Desktop/solid-demo) +0ms
vite:esbuild init tsconfck (root: C:/Users/lihe07/Desktop/solid-demo) +3ms
vite:esbuild init tsconfck (root: C:/Users/lihe07/Desktop/solid-demo) +1ms
vite:esbuild init tsconfck (root: C:/Users/lihe07/Desktop/solid-demo) +0ms
vite:esbuild init tsconfck end +16ms
vite:esbuild init tsconfck end +1ms
vite:esbuild init tsconfck end +0ms
vite:esbuild init tsconfck end +0ms
vite:config using resolved config: {
vite:config plugins: [
vite:config 'vite:build-metadata',
vite:config 'vite:pre-alias',
vite:config 'alias',
vite:config 'solid',
vite:config 'unocss:transformers:pre',
vite:config 'unocss:global:build:scan',
vite:config 'vite:modulepreload-polyfill',
vite:config 'vite:resolve',
vite:config 'vite:html-inline-proxy',
vite:config 'vite:css',
vite:config 'vite:esbuild',
vite:config 'vite:json',
vite:config 'vite:wasm-helper',
vite:config 'vite:worker',
vite:config 'vite:asset',
vite:config 'unocss:config',
vite:config 'unocss:transformers:default',
vite:config 'unocss:devtools',
vite:config 'vite:wasm-fallback',
vite:config 'vite:define',
vite:config 'vite:css-post',
vite:config 'vite:build-html',
vite:config 'vite:worker-import-meta-url',
vite:config 'vite:asset-import-meta-url',
vite:config 'vite:force-systemjs-wrap-complete',
vite:config 'vite:watch-package-data',
vite:config 'commonjs',
vite:config 'vite:data-uri',
vite:config 'vite:dynamic-import-vars',
vite:config 'vite:import-glob',
vite:config 'unocss:transformers:post',
vite:config 'unocss:global:build:generate',
vite:config 'vite:build-import-analysis',
vite:config 'vite:esbuild-transpile',
vite:config 'vite:terser',
vite:config 'vite:reporter',
vite:config 'vite:load-fallback'
vite:config ],
vite:config build: {
vite:config target: 'esnext',
vite:config cssTarget: 'esnext',
vite:config outDir: 'dist',
vite:config assetsDir: 'assets',
vite:config assetsInlineLimit: 4096,
vite:config cssCodeSplit: true,
vite:config sourcemap: false,
vite:config rollupOptions: {},
vite:config minify: 'esbuild',
vite:config terserOptions: {},
vite:config write: true,
vite:config emptyOutDir: null,
vite:config copyPublicDir: true,
vite:config manifest: false,
vite:config lib: false,
vite:config ssr: false,
vite:config ssrManifest: false,
vite:config reportCompressedSize: true,
vite:config chunkSizeWarningLimit: 500,
vite:config watch: null,
vite:config commonjsOptions: { include: [Array], extensions: [Array] },
vite:config dynamicImportVarsOptions: { warnOnError: true, exclude: [Array] },
vite:config modulePreload: { polyfill: true }
vite:config },
vite:config optimizeDeps: {
vite:config disabled: 'build',
vite:config force: undefined,
vite:config include: [],
vite:config exclude: [],
vite:config esbuildOptions: { preserveSymlinks: false }
vite:config },
vite:config resolve: {
vite:config mainFields: [ 'module', 'jsnext:main', 'jsnext' ],
vite:config browserField: true,
vite:config conditions: [ 'solid' ],
vite:config extensions: [
vite:config '.mjs', '.js',
vite:config '.mts', '.ts',
vite:config '.jsx', '.tsx',
vite:config '.json'
vite:config ],
vite:config dedupe: [],
vite:config preserveSymlinks: false,
vite:config alias: [ [Object], [Object], [Object] ]
vite:config },
vite:config esbuild: { include: /.ts$/ },
vite:config ssr: {
vite:config format: 'esm',
vite:config target: 'node',
vite:config noExternal: [],
vite:config external: [],
vite:config optimizeDeps: { disabled: true, esbuildOptions: [Object] }
vite:config },
vite:config configFile: 'C:/Users/lihe07/Desktop/solid-demo/vite.config.js',
vite:config configFileDependencies: [ 'C:/Users/lihe07/Desktop/solid-demo/vite.config.js' ],
vite:config inlineConfig: {
vite:config root: undefined,
vite:config base: undefined,
vite:config mode: undefined,
vite:config configFile: undefined,
vite:config logLevel: undefined,
vite:config clearScreen: undefined,
vite:config optimizeDeps: { force: undefined },
vite:config build: {}
vite:config },
vite:config root: 'C:/Users/lihe07/Desktop/solid-demo',
vite:config base: '/',
vite:config publicDir: 'C:\Users\lihe07\Desktop\solid-demo\public',
vite:config cacheDir: 'C:\Users\lihe07\Desktop\solid-demo\node_modules\.vite',
vite:config command: 'build',
vite:config mode: 'production',
vite:config isWorker: false,
vite:config mainConfig: null,
vite:config isProduction: true,
vite:config server: {
vite:config preTransformRequests: true,
vite:config middlewareMode: false,
vite:config fs: { strict: true, allow: [Array], deny: [Array] }
vite:config },
vite:config preview: {
vite:config port: undefined,
vite:config strictPort: undefined,
vite:config host: undefined,
vite:config https: undefined,
vite:config open: undefined,
vite:config proxy: undefined,
vite:config cors: undefined,
vite:config headers: undefined
vite:config },
vite:config env: { BASE_URL: '/', MODE: 'production', DEV: false, PROD: true },
vite:config assetsInclude: [Function: assetsInclude],
vite:config logger: {
vite:config hasWarned: false,
vite:config info: [Function: info],
vite:config warn: [Function: warn],
vite:config warnOnce: [Function: warnOnce],
vite:config error: [Function: error],
vite:config clearScreen: [Function: clearScreen],
vite:config hasErrorLogged: [Function: hasErrorLogged]
vite:config },
vite:config packageCache: Map(0) { set: [Function (anonymous)] },
vite:config createResolver: [Function: createResolver],
vite:config worker: {
vite:config format: 'iife',
vite:config plugins: [
vite:config 'vite:build-metadata',
vite:config 'vite:pre-alias',
vite:config 'alias',
vite:config 'vite:modulepreload-polyfill',
vite:config 'vite:resolve',
vite:config 'vite:html-inline-proxy',
vite:config 'vite:css',
vite:config 'vite:esbuild',
vite:config 'vite:json',
vite:config 'vite:wasm-helper',
vite:config 'vite:worker',
vite:config 'vite:asset',
vite:config 'vite:wasm-fallback',
vite:config 'vite:define',
vite:config 'vite:css-post',
vite:config 'vite:build-html',
vite:config 'vite:worker-import-meta-url',
vite:config 'vite:asset-import-meta-url',
vite:config 'vite:force-systemjs-wrap-complete',
vite:config 'vite:watch-package-data',
vite:config 'commonjs',
vite:config 'vite:data-uri',
vite:config 'vite:dynamic-import-vars',
vite:config 'vite:import-glob',
vite:config 'vite:build-import-analysis',
vite:config 'vite:esbuild-transpile',
vite:config 'vite:terser',
vite:config 'vite:reporter',
vite:config 'vite:load-fallback'
vite:config ],
vite:config rollupOptions: {},
vite:config getSortedPlugins: [Function: getSortedPlugins],
vite:config getSortedPluginHooks: [Function: getSortedPluginHooks]
vite:config },
vite:config appType: 'spa',
vite:config experimental: { importGlobRestoreExtension: false, hmrPartialAccept: false },
vite:config getSortedPlugins: [Function: getSortedPlugins],
vite:config getSortedPluginHooks: [Function: getSortedPluginHooks]
vite:config } +472ms
vite v3.2.2 building for production...
✓ 7 modules transformed.
rendering chunks (1)...[vite:build-html] The "fileName" or "name" properties of emitted files must be strings that are neither absolute nor relative paths, received "D:/Users/lihe07/Desktop/solid-demo/index.html".
error during build:
Error: The "fileName" or "name" properties of emitted files must be strings that are neither absolute nor relative paths, received "D:/Users/lihe07/Desktop/solid-demo/index.html".
at error (file:///D:/Users/lihe07/Desktop/solid-demo/node_modules/_rollup@2.79.1@rollup/dist/es/shared/rollup.js:1858:30)
at FileEmitter.emitFile (file:///D:/Users/lihe07/Desktop/solid-demo/node_modules/_rollup@2.79.1@rollup/dist/es/shared/rollup.js:22335:24)
at Object.generateBundle (file:///D:/Users/lihe07/Desktop/solid-demo/node_modules/_vite@3.2.2@vite/dist/node/chunks/dep-c842e491.js:44203:22)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Bundle.generate (file:///D:/Users/lihe07/Desktop/solid-demo/node_modules/_rollup@2.79.1@rollup/dist/es/shared/rollup.js:15796:9)
at async file:///D:/Users/lihe07/Desktop/solid-demo/node_modules/_rollup@2.79.1@rollup/dist/es/shared/rollup.js:23795:27
at async catchUnfinishedHookActions (file:///D:/Users/lihe07/Desktop/solid-demo/node_modules/_rollup@2.79.1@rollup/dist/es/shared/rollup.js:23126:20)
at async doBuild (file:///D:/Users/lihe07/Desktop/solid-demo/node_modules/_vite@3.2.2@vite/dist/node/chunks/dep-c842e491.js:46588:22)
at async build (file:///D:/Users/lihe07/Desktop/solid-demo/node_modules/_vite@3.2.2@vite/dist/node/chunks/dep-c842e491.js:46416:16)
at async CAC. (file:///D:/Users/lihe07/Desktop/solid-demo/node_modules/_vite@3.2.2@vite/dist/node/cli.js:756:9)

Validations

@sapphi-red
Copy link
Member

This seems to happen with symlinks #10978 (OP is using junctions).
I guess we are missing fs.realpath.native somewhere.

@sapphi-red
Copy link
Member

I guess this is related with nodejs/node#34866.

@MichaelGoulding
Copy link

This prevented me from moving from webpack to vite

@PickleNik
Copy link

This prevented me from moving from webpack to vite

skill issue honestly

@shijh
Copy link

shijh commented Jul 22, 2023

I got a similar issue, it's reported this line wrong with soft link on windows:
const shortEmitName = normalizePath$3(path$o.relative(config.root, id));

I'm not sure whether it's related to:

const shortEmitName = normalizePath(path.relative(config.root, id))

Error while run command 'npm run build' as screenshot below:
vite-windows-softlink-build-error

@shijh
Copy link

shijh commented Jul 23, 2023

Sorry the above message. It's resolved by setting resolve.preserveSymlinks to true, works like a charm.

@sapphi-red sapphi-red changed the title Vite failed with projects involving soft links on Windows Vite failed with projects involving cross drive links on Windows Aug 2, 2023
@EmperorArthur
Copy link

@sapphi-red I'm seeing the same problem when trying to run Vite from a mapped drive. It's a corporate environment so I don't have a choice.

Anonymized error for something like "\server1.mycompany.com\myProject" mapped to "T:".

[vite:load-fallback] Could not load /server1/myProject/src/app.tsx (imported by index.html): ENOENT: no such file or directory, open 'T:\server1.mycompany.com\myProject\src\app.tsx'

I've determined that the realpath function is giving the correct path, but something is converting it to POSIX format which then breaks path.resolve

Example function output:

const promises = require('node:fs/promises')
await promises.realpath('.')

Proposed Solution(s)

The suggestion by @shijh worked! However, was not required until just after version 4.1.4. I was just lucky someone else had a similar issue.

  • Add behavior to check for network drive format (can be done using path.toNamespacedPath)
  • Add fallback behavior to use "resolve.preserveSymlinks = true" if a file can't be found along with a warning
  • Add additional error information, or a suggestion on how to fix the problem in the error message.
  • Actually fix whatever function is incorrectly converting to POSIX paths and assuming that paths never cross drive boundaries.

Open Questions

Which function is converting to POSIX paths, while dropping drive letters / network share information?

@EmperorArthur
Copy link

EmperorArthur commented Oct 5, 2023

Edit: Originally thought there was a Node bug, but it's really a naming/documentation issue causing confusion.

The problem is the promises based version of "realpath" is really for "realpath.native"! It's mentioned in the documentation but it's easy to overlook.

fs.realpath('T:', (e,r) => console.log(r)) // Gives "T:\\"
fs.realpath.native('T:', (e,r) => console.log(r)) // Gives "\\\\ServerName\\\MountedDirectory"
fs.realpathSync('T:') // Gives "T:\\"
fs.realpathSync.native('T:') // Gives "\\\\ServerName\\\MountedDirectory"

// The problem
await fs.promises.realpath('T:') // Gives "\\\\ServerName\\\MountedDirectory"

@danielvandenberg95
Copy link

So the cause has been known for over half a year. It this issue expected to be fixed any time soon? Doesn't seem like it should be difficult to someone familiar with contributing to vite?

@EmperorArthur
Copy link

So the cause has been known for over half a year.

Unfortunately, there are multiple different problems. My issue, which deals with network drives is caused by fs.promises.realpath.
Then there's normalizePath and similar not handling certain strings and producing garbage.

I can't fix it during work hours without getting approval to contribute to an Open Source project, and the issue's I'm experiencing are solely related to the work environment. No one sane who has a choice does development with source code on a network share.

@fabioz
Copy link

fabioz commented Jun 29, 2024

As a note, I had a similar issue and setting resolve.preserveSymlinks: true in the vite.config.js did fix it here too (same as a comment above).

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

No branches or pull requests

8 participants