Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using JavaScript API of "build" and "createServer" at the same time will cause HMR error. #8204

Closed
7 tasks done
qq326943819 opened this issue May 18, 2022 · 2 comments · Fixed by #8230
Closed
7 tasks done

Comments

@qq326943819
Copy link

qq326943819 commented May 18, 2022

Describe the bug

When I run the local server with "build" and "createServer" at the same time, the page can't perform HMR.

Reproduction

https://stackblitz.com/edit/node-nuu1gt?file=build%2Fdev-runner.js,src%2FApp.vue

System Info

OS: Windows 10 10.0.19043
    CPU: (16) x64 AMD Ryzen 7 5800H with Radeon Graphics
    Memory: 5.51 GB / 15.36 GB
Binaries:
  Node: 16.15.0 - C:\Program Files\nodejs\node.EXE
  npm: 8.5.5 - C:\Program Files\nodejs\npm.CMD
Browsers:
  Edge: Spartan (44.19041.1266.0), Chromium (101.0.1210.47)
  Internet Explorer: 11.0.19041.1566
npmPackages:
  @vitejs/plugin-vue: ^2.3.3 => 2.3.3
  vite: ^2.9.9 => 2.9.9

Used Package Manager

npm

Logs

No response

Validations

@bluwy
Copy link
Member

bluwy commented May 18, 2022

This is because when building, Vite will set process.env.NODE_ENV to production which wouldn't work in dev mode and Vue HMR fails as they HMR code isn't injected correctly. A solution is to run the build in dev mode too, passing mode: 'development' to the build config.

This issue isn't really easy to solve by Vite as process.env.NODE_ENV is a shared variable used by plugins too. So if you need to run the build in production, you can spawn another process to run it.

@qq326943819
Copy link
Author

This is because when building, Vite will set process.env.NODE_ENV to production which wouldn't work in dev mode and Vue HMR fails as they HMR code isn't injected correctly. A solution is to run the build in dev mode too, passing mode: 'development' to the build config.

This issue isn't really easy to solve by Vite as process.env.NODE_ENV is a shared variable used by plugins too. So if you need to run the build in production, you can spawn another process to run it.

Thanks,I temporarily use the mode change method.

@github-actions github-actions bot locked and limited conversation to collaborators Jun 3, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants