Skip to content

HMR is broken when encounter top-level undefined variables #68

Closed
@fifv

Description

@fifv

Describe the bug

Use yarn vite create with React and Typescript
At App.tsx's top-level, type random letters, then error occurs:
image
Then remove these invalid variables, but hmr not works. No auto refresh or error messages anymore, just frozen.
I have to refresh page manually to make it works again.
There is no problem in the vite-plugin-react-swc. (but debugging seems not work in vite-plugin-react-swc, I have to use vite-plugin-react )

Reproduction

yarn create vite (with React and Typescript)

Steps to reproduce

  1. yarn create vite with React and Typescript
  2. yarn dev
  3. type any letter at the top-level of App.tsx
  4. save file

Now hmr not works any more until manually refreshing the page.

System Info

System:
    OS: Windows 10 10.0.22623
    CPU: (16) x64 AMD Ryzen 7 4800H with Radeon Graphics
    Memory: 7.22 GB / 31.87 GB
  Binaries:
    Node: 18.12.1 - ~\AppData\Local\Temp\xfs-3a75f462\node.CMD
    Yarn: 3.3.0 - ~\AppData\Local\Temp\xfs-3a75f462\yarn.CMD
    npm: 7.24.1 - D:\Documents\....\npm.CMD
  Browsers:
    Edge: Spartan (44.22621.1037.0), Chromium (108.0.1462.54)
    Internet Explorer: 11.0.22621.1
  npmPackages:
    @vitejs/plugin-react: ^3.0.0 => 3.0.0
    vite: ^4.0.0 => 4.0.2

Used Package Manager

yarn

Logs

Click to expand!
vite:hmr [file change] src/App.tsx +8s
2:15:43 [vite] hmr update /src/App.tsx
  vite:load 0.59ms [fs] /src/App.tsx +8s
  vite:import-analysis /node_modules/.vite/deps/react.js?v=4fd75b4d needs interop +8s
  vite:hmr [self-accepts] src\App.tsx +27ms
  vite:import-analysis 7.79ms [5 imports rewritten] src\App.tsx +7ms
  vite:transform 20.08ms /src/App.tsx +8s
  vite:cache [memory] /@react-refresh +8s
  vite:cache [memory] /node_modules/.vite/deps/react.js?v=4fd75b4d +1ms
  vite:cache [memory] /src/assets/react.svg +0ms
  vite:cache [memory] /src/App.css +0ms
  vite:cache [memory] react/jsx-dev-runtime +0ms
  vite:time 26.71ms /src/App.tsx +6s
2:15:43 [vite] hmr invalidate /src/App.tsx
2:15:43 [vite] page reload src/App.tsx
  vite:html-fallback Rewriting GET / to /index.html +7s
  vite:time 3.85ms /index.html +20ms
  vite:cache [304] /@vite/client +6s
  vite:time 1.26ms /@vite/client +16ms
  vite:load 0.35ms [fs] /src/main.tsx +106ms
  vite:import-analysis /node_modules/.vite/deps/react.js?v=4fd75b4d needs interop +94ms
  vite:import-analysis /node_modules/.vite/deps/react-dom_client.js?v=9b546806 needs interop +2ms
  vite:import-analysis 9.89ms [5 imports rewritten] src\main.tsx +7ms
  vite:transform 18.15ms /src/main.tsx +103ms
  vite:cache [memory] /node_modules/.vite/deps/react.js?v=4fd75b4d +103ms
  vite:cache [memory] /node_modules/.vite/deps/react-dom_client.js?v=9b546806 +1ms
  vite:cache [memory] /src/App.tsx +0ms
  vite:cache [memory] /src/index.css +0ms
  vite:cache [memory] react/jsx-dev-runtime +1ms
  vite:time 25.31ms /src/main.tsx +69ms
  vite:cache [304] /@react-refresh +85ms
  vite:time 0.58ms /@react-refresh +17ms
  vite:cache [304] /node_modules/vite/dist/client/env.mjs +3ms
  vite:time 1.85ms /node_modules/vite/dist/client/env.mjs +3ms
  vite:cache [304] react/jsx-dev-runtime +2ms
  vite:time 0.53ms /@id/__x00__react/jsx-dev-runtime +1ms
  vite:cache [304] /src/App.tsx +7ms
  vite:time 1.83ms /src/App.tsx +8ms
  vite:cache [304] /src/index.css +3ms
  vite:time 1.20ms /src/index.css +2ms
  vite:cache [304] /src/assets/react.svg +28ms
  vite:time 1.73ms /src/assets/react.svg?import +28ms
  vite:cache [304] /src/App.css +3ms
  vite:time 1.96ms /src/App.css +3ms
  vite:time 1.85ms /node_modules/.vite/deps/react_jsx-dev-runtime.js.map +11ms
  vite:time 3.39ms /node_modules/.vite/deps/chunk-2T7YCMPZ.js.map +2ms
  vite:time 1.55ms /node_modules/.vite/deps/react.js.map +4ms
  vite:time 15.71ms /node_modules/.vite/deps/react-dom_client.js.map +15ms
  vite:time 0.61ms /vite.svg +9ms

Validations

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions