vite: Inconsistent SSR require/import paths on Windows

Describe the bug

The following entries appear in require.cache on Windows…

[
  'C:\\DevTemp\\my-app\\node_modules\\solid-js\\web\\dist\\server.cjs',
  'C:/DevTemp/my-app/node_modules/solid-js/dist/server.cjs',
  'C:\\DevTemp\\my-app\\node_modules\\solid-js\\dist\\server.cjs'
]

Note the 2nd and 3rd paths above refer to the same file.
Whereas on Linux in the same project we see…

[
  '/home/brendan/devtemp/my-app/node_modules/solid-js/web/dist/server.cjs',
  '/home/brendan/devtemp/my-app/node_modules/solid-js/dist/server.cjs'
]

The second entry results from a require() call within the preceding .cjs file. Whereas the others result from Vite calling its dynamicImport() function.

On Windows the duplication of the second and third import above results in errors in this particular library as it is expected to run once.

These were observed by calling console.log(Object.keys(require.cache).filter(k => k.includes("solid-js"))) in strategic locations on both OSs.

Reproduction

mkdir my-app
cd my-app
npm init solid@next  (choose Typescript)
npm install
npm run dev

Browse http://localhost:3000/ and observe an error (on Windows only).

Add this console log somewhere: console.log(Object.keys(require.cache).filter(k => k.includes("solid-js"))) eg. line 67385 of node_modules\vite\dist\node\chunks\dep-3daf770c.js

    try {
        const mod = await dynamicImport(url);
        console.log(Object.keys(require.cache).filter(k => k.includes("solid-js")))
        return proxyESM(mod);
    }
    finally {
        unhookNodeResolve();
    }

Observe the above mentioned require.cache entries differ from Windows to Linux.

System Info

System:
    OS: Windows 10 10.0.22000
    CPU: (12) x64 Intel(R) Core(TM) i7-10750H CPU @ 2.60GHz
    Memory: 5.52 GB / 15.72 GB
  Binaries:
    Node: 16.13.1 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.5 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
    npm: 8.3.0 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.22000.120.0), Chromium (96.0.1054.43)
    Internet Explorer: 11.0.22000.120
  npmPackages:
    vite: ^2.7.1 => 2.7.1

Used Package Manager

npm

Logs

No response

Validations

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 4
  • Comments: 16 (2 by maintainers)

Commits related to this issue

Most upvoted comments

This issue seems to be resolved in 2.7.13. Thanks to all involved!

Thank you @Brendan-csel for all the testing in the issue!