aleclarson / vite-tsconfig-paths

Support for TypeScript's path mapping in Vite
MIT License
1.35k stars 50 forks source link

Regression 3.3.2 -> 3.3.3 #19

Closed gunters63 closed 3 years ago

gunters63 commented 3 years ago

Updating from 3.3.2 to 3.3.3 breaks dev server and build with the following error:

error during build:
Error: ENOENT: no such file or directory, stat 'D:\proj\AtlasCopco\EnsoUi/D:/proj/AtlasCopco/EnsoUi/tsconfig.json'
    at Object.statSync (fs.js:1086:3)
    at resolveConfigPath (D:\proj\AtlasCopco\EnsoUi\node_modules\.pnpm\tsconfig-paths@3.9.0\node_modules\tsconfig-paths\lib\tsconfig-loader.js:48:12)
    at loadSyncDefault (D:\proj\AtlasCopco\EnsoUi\node_modules\.pnpm\tsconfig-paths@3.9.0\node_modules\tsconfig-paths\lib\tsconfig-loader.js:26:22)

I am using Windows and Node 14 LTS. I guess some recent changes broke path handling on Windows.

aleclarson commented 3 years ago

I'm gonna get some tests going before I publish my suspected fix.

aleclarson commented 3 years ago

Okay, try out 3.3.6 in your project. :)

If that fails, please write a failing test (here) and open a PR. 👍

To run tests locally:

git clone https://github.com/aleclarson/vite-tsconfig-paths
cd vite-tsconfig-paths
pnpm install
yarn test --watch -i
gunters63 commented 3 years ago

I still get a crash with 3.3.6, in a different place.

image

After executing the line:

 projectPath = resolve(root, vite_1.normalizePath(projectPath))

projectPath is "D:\\proj\\AtlasCopco\\EnsoUi/D:/proj/AtlasCopco/EnsoUi/tsconfig.json"

gunters63 commented 3 years ago

The posix.resolve call gets correct parameters it seems:

image

gunters63 commented 3 years ago
import { posix }  from 'path'
const { join, resolve } = posix

Pretty sure these posix Node api calls do not work on Windows

aleclarson commented 3 years ago

Follow the instructions in Troubleshooting, and paste the logs here.

You can also write a failing test here and open a PR with it (no fix necessary).

git clone https://github.com/aleclarson/vite-tsconfig-paths
cd vite-tsconfig-paths
pnpm install
yarn test --watch -i
aleclarson commented 3 years ago

@gunters63 What options are you passing to the plugin?

aleclarson commented 3 years ago

Okay, I see what you mean about the path.posix incompatibility. Working on a fix!

aleclarson commented 3 years ago

Windows paths should be fixed in v3.3.7

aleclarson commented 3 years ago

And include bugs are fixed in v3.3.8

gunters63 commented 3 years ago

I can confirm 3.3.8 is working again :)

What I didn't understand in the fix is the need to detect the OS manually, for example calling path.win32.resolve on Windows and path.posix.resolve on other platforms. Wouldn't just calling path.resolve work?

aleclarson commented 3 years ago

Wouldn't just calling path.resolve work?

win32.resolve converts / to \\, and the plugin internals expect / separators only