vitejs / vite-plugin-react-swc

Speed up your Vite dev server with SWC
MIT License
834 stars 54 forks source link

Debug is broken when use CRLF line break #31

Closed fifv closed 1 year ago

fifv commented 1 year ago

Reproduce:

  1. yarn create vite with React and Typescript

  2. edit App.tsx like this:

/* 

these empty lines in the comment block will break debugging

*/

export default function App() {
    console.log('App');  // breakpoint here
    return (
        <div>
            test
        </div>
    )
}
  1. Change App.tsx line break to CRLF
  2. Set breakpoint at line console.log('App');
  3. Start debug, but breakpoint hit at a weird place: image If set breakpoint at devtool, it get misplaced. image

Here is my launch.json:

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "chrome",
      "request": "launch",
      "name": "Launch Chrome against localhost",
      "url": "http://localhost:5173",
      "webRoot": "${workspaceFolder}/src" // This works, but i still don't know why after a lot of search. CRA and esbuild+liveserver also only works with this path.
    }
  ]
}

vite.config.ts

import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react-swc'
export default defineConfig({
  plugins: [react()],
  server: {
    host: '0.0.0.0' // the default 'localhost' makes browser and vscode fails to fetch sourcemap, due to some CORS error, idk why.
  }
})

Sysinfo:

Click to expand! ``` System: OS: Windows 10 10.0.22623 CPU: (16) x64 AMD Ryzen 7 4800H with Radeon Graphics Memory: 10.07 GB / 31.87 GB Binaries: Node: 18.12.1 - ~\AppData\Local\Temp\xfs-dce58dc0\node.CMD Yarn: 3.3.0 - ~\AppData\Local\Temp\xfs-dce58dc0\yarn.CMD npm: 7.24.1 - D:\Documents\_JavaScript\node_global\npm.CMD Browsers: Edge: Spartan (44.22621.1037.0), Chromium (108.0.1462.54) Internet Explorer: 11.0.22621.1 npmPackages: @vitejs/plugin-react-swc: ^3.0.0 => 3.0.1 vite: ^4.0.0 => 4.0.2 ```
ArnaudBarre commented 1 year ago

Blocked by upstream: https://github.com/swc-project/swc/issues/6694

kdy1 assigned recently so maybe this can be fixed quickly.

Keeping open, but I would advice using linux line break everywhere anyway. I think this can be enforced by Prettier or git.

ArnaudBarre commented 1 year ago

Fixed upstream