Skip to content

"Component is missing template or render function" after HMR #610

Description

@icehaunter

Describe the bug

When using Vite with Vue 3, regularly a component update will cause the component to vanish from the browser page and the following error will be presented: "Component is missing template or render function". This can be caused by a change as small as adding whitespace to the script block.

image

I have noticed that the issue is present across all components for me, whether they use object syntax, composition API, or the new <script setup> block. I am using TypeScript exclusively, but the root component (App.vue from the standard init script) also had the same problem despite not using TS.

Reproduction

The behavior was demonstrated in vuejs/core#1620 (comment) when I did a reproduction of a different bug - pay attention to the browser console. That recording uses older Vue/Vite, but the problem is reproducible for me on the latest versions.

Here is reproduction repo (it is the same as in the issue above, but I updated dependencies and checked again - error is still present). I tested the issue in Chrome and Firefox.

Steps

  1. Clone repo and npm ci
  2. Run npm run dev and open browser
  3. Update components/HelloWorld.vue multiple times, for example adding a line break after <script>
  4. See that, after several successful reloads, the component is not rendered and a warning is printed to console
  5. Save the file multiple times again (even without any changes) and see that component is rendered again

Update

After some experimenting, I found that the error stems from file saving. VSCode saved files somehow differently to, say, Vim, and seems to save multiple times quickly, even without any plugins enabled.

I managed to boil the reproduction down to a script, which is now present in the reproduction repo. And so, the new steps are:
3. Execute node ./reproduce_bug.mjs
4. See that the component is not rendered and a warning is printed to browser console

Screenshots

Error:

image

Valid again:

image

System Info

  • required vite version: 1.0.0-rc.3
  • required Operating System: Arch Linux (x86_64 Linux 5.7.7-arch1-1)
  • required Node version: 14.5.0
  • Optional:
    • npm version: npm 6.14.6
    • Installed vue version (from yarn.lock or package-lock.json): 3.0.0-rc.4
    • Installed @vue/compiler-sfc version: "@vue/compiler-core"

Activity

  1. icehaunter commented on Jul 23, 2020

    @icehaunter
    Author

    This bug can be very annoying when working with multiple nested components and changing them all at once because after that you have to go through each and make sure it renders properly by just hitting save multiple times.

  2. icehaunter commented on Jul 30, 2020

    @icehaunter
    Author

    Bug is still present on Vue 3.0.0-rc.5

  3. yyx990803 commented on Jul 30, 2020

    @yyx990803
    Member

    This is quite weird as I've never ran into this and I can't reproduce it even using the exact dependencies in your repro (via npm ci) on macOS. This may be a Linux only problem?

    For other people upvoting this issue - could you share your system environment?

  4. Ltyi commented on Jul 31, 2020

    @Ltyi

    System Info

    • vite 1.0.0-rc.4
    • vue 3.0.0-rc.5
    • OS: Windows 10

    Steps

    1. npm init vite-app issue-test
    2. cd issue-test
    3. npm install
    4. npm run dev
    5. edit components/HelloWorld.vue, adding a line break after count: 0 and save
    6. do step 5 multiple times

    In my case, if it diden't happen, shut down terminal and run npm run dev again

  5. mrDlef commented on Aug 1, 2020

    @mrDlef

    Hi, same problem here with vite 1.0.0-rc.4 on Firefox 79.0 (64 bits) and Ubuntu 20.04.1 LTS.

  6. natasher commented on Aug 3, 2020

    @natasher

    System Info

    • vite 1.0.0-rc.1
    • vue 3.0.0-rc.1
    • OS: Manjaro Linux Kernel 4.19.133-1
  7. icehaunter commented on Aug 9, 2020

    @icehaunter
    Author

    @yyx990803, I tried to make the issue more reproducible. I took to docker and tired out multiple versions of the node. After bug reproduced easily for me on any recent version, I tried paying attention to how I edit the file. Turned out, using Vim/Nano does not reproduce the bug: only using VSCode does, even without any extensions enabled.

    Blaming VSCode is strange because it's just an editor, so I thought that it differs in working with files somehow. And so, I found a stable reproduction case (at least for me). It was added to the original repo as a .mjs script to be run with node after starting the server. What it does, is it adds and then removes a line break in a script section of the file without any delay. I think that those quick consecutive saves are what is causing the problem because as soon as I run the script, error immediately shows up in the browser console.

    I don't know who should investigate the issue: it might be Vite's file watching bug, or it might be an undocumented behaviour of VSCode. If the issue is still not reproducible for you, please let me know, I'll try some over OS's and try to pinpoint the issue.

  8. icehaunter commented on Aug 9, 2020

    @icehaunter
    Author

    @yyx990803, I managed to reproduce the bug using the updated repo with the script on the latest macOS.

  9. fyZhang66 commented on Aug 10, 2020

    @fyZhang66

    Same problem happened in vue@3.0.0-rc.1 & vite@3.0.0-rc.1 and windows7. I found if i restart the terminal the problem can be solved

  10. au-top commented on Aug 25, 2020

    @au-top

    The same problem happened
    Is there any way to alleviate it
    vite@1.0.0-rc.4
    vue3.0@rc.5
    OS: debian10

  11. icehaunter commented on Aug 27, 2020

    @icehaunter
    Author

    Could anyone leaving a comment with their environment also specify which editor they use? I still think the issue lies in a way some editors save their files and how the saving is tracked.

  12. mzgajner commented on Sep 1, 2020

    @mzgajner

    @icehaunter you're correct.

    I can reproduce the issue on Ubuntu 20.04, vite@1.0.0-rc.4, vue@3.0.0-rc.9 with Visual Studio Code (tried both regular and Insiders version, installed through snap and apt), but it immediately goes away if I switch to any other editor (tried vim, nano, PyCharm and the default Text Editor that comes with Gnome).

  13. 7 remaining items

  14. added a commit that references this issue on Sep 17, 2020
    cdac398
  15. added a commit that references this issue on Sep 17, 2020
    a8f9595
  16. underfin commented on Sep 17, 2020

    @underfin
    Member

    Thanks all guys great catch:)

  17. dominikg commented on Sep 17, 2020

    @dominikg
    Contributor

    Great, this could be the solution to some annoying test-suite timeouts i got in svite when writing files with node fs.

    Did you test the settings with slow hardware (eg. old 5400rpm hdd under load)? The chosen values for awaitWriteFinish seem a bit low.
    There are also some open issues about this setting on chokidar repo: https://github.com/paulmillr/chokidar/issues?q=is%3Aissue+is%3Aopen+awaitWriteFinish (not working on windows, symlink problem on linux).

    Could it be possible to expose the watcher setup/config so users can optimize it for their platform/needs? (with sensible defaults ofc)

  18. Demon000 commented on Sep 21, 2020

    @Demon000

    Could a release be made? This is a pretty important issue and really annoying. It also happens with WebStorm and I couldn't find any settings affecting how the IDE saves files to get around it.

  19. palerdot commented on Oct 2, 2020

    @palerdot

    This issue still persists for people trying out Vue 3 RC. Potential fix for this issue is also still open and yet to be merged - #841. Can this issue be reopened?

  20. palerdot commented on Oct 2, 2020

    @palerdot

    This issue still persists for people trying out Vue 3 RC. Potential fix for this issue is also still open and yet to be merged - #841. Can this issue be reopened?

    I stand corrected. It seems the fix is merged here - #824.

    Still, please reopen this issue till a release is made and confirmed that it fixes this issue.

  21. jhadenfeldt commented on Oct 13, 2020

    @jhadenfeldt

    Is there an ETA when this is going to be released? Currently the issue still exists with the latest released version.

  22. Niputi commented on Oct 13, 2020

    @Niputi
    Contributor
  23. mzgajner commented on Oct 14, 2020

    @mzgajner

    The easiest temporary fix is to follow these instructions and use the latest vite master locally - it's just a local change that doesn't require any changes to the project you're working on.

  24. added a commit that references this issue on Dec 6, 2020
  25. locked and limited conversation to collaborators on Jul 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions