Skip to content

Vite HMR not working . Changing code does not reflect on page until restart vite server #16284

Description

@neodino

Describe the bug

I setup a basic react+ts template and expect HMR to work. But It does not.
When I change some values inside App.tsx / main.tsx or any components, it does not updates in browser.
I'm on macOS m1 using vite 5.2.6 and node 18.

I did setup chokidar simple test to check if events get trigged. It works!

Reproduction

pnpm list
Legend: production dependency, optional only, dev only

dependencies:
@reduxjs/toolkit 2.2.2     globals 14.0.0             react-redux 9.1.0          
antd 5.15.4                lodash 4.17.21             styled-components 6.1.8    
chokidar 3.6.0             react 18.2.0               twin.macro 3.4.1           
flexlayout-react 0.7.15    react-dom 18.2.0           vite 5.2.6                 
fsevents 2.3.3             react-icons 5.0.1          vite-tsconfig-paths 4.3.2  

devDependencies:
@openapitools/openapi-generator-cli 2.13.1  eslint 8.57.0                               
@types/node 20.11.30                        eslint-plugin-react-hooks 4.6.0             
@types/react 18.2.72                        eslint-plugin-react-refresh 0.4.6           
@types/react-dom 18.2.22                    openapi-typescript-codegen 0.25.0           
@typescript-eslint/eslint-plugin 7.4.0      sass 1.72.0                                 
@typescript-eslint/parser 7.4.0             tailwindcss 3.4.1                           
@vitejs/plugin-react 4.2.1                  typescript 5.4.3                

cat index.cjs 
const chokidar = require('chokidar');

// One-liner for current directory
chokidar.watch('**/*.tsx').on('all', (event, path) => {
  console.log(event, path);
});
-------
----
--
add node_modules/.pnpm/@ampproject+remapping@2.3.0/node_modules/@jridgewell/trace-mapping/dist/types/trace-mapping.d.ts
add node_modules/.pnpm/@ampproject+remapping@2.3.0/node_modules/@jridgewell/trace-mapping/dist/types/types.d.ts
**change src/components/News/index.tsx**

http://google.com

Steps to reproduce

 npm create vite@latest
✔ Project name: … test-vite
✔ Select a framework: › React
✔ Select a variant: › TypeScript

Scaffolding project in 

Done. Now run:

  cd test-vite
  npm install
  npm run dev

 npm install

added 218 packages, and audited 219 packages in 7s

41 packages are looking for funding
  run `npm fund` for details

System Info

npx envinfo --system --npmPackages '{vite,@vitejs/*,rollup}' --binaries --browsers
Need to install the following packages:
envinfo@7.11.1
Ok to proceed? (y) y

  System:
    OS: macOS 13.6.5
    CPU: (10) arm64 Apple M1 Pro
    Memory: 169.16 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.19.1 - ~/Library/Caches/fnm_multishells/80450_1711424646646/bin/node
    Yarn: 1.22.18 - /usr/local/bin/yarn
    npm: 10.2.4 - ~/Library/Caches/fnm_multishells/80450_1711424646646/bin/npm
    pnpm: 8.15.5 - ~/Library/pnpm/pnpm
  Browsers:
    Chrome: 123.0.6312.59
    Safari: 17.4
  npmPackages:
    @vitejs/plugin-react: ^4.2.1 => 4.2.1
    vite: ^5.2.0 => 5.2.6

Used Package Manager

npm

Logs

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions