You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Create a Vue project with components using Vue 3.x.
Bundle Vue components separately from the server-side rendering logic using Webpack (using webpack-vue.config.js).
Use the bundled components in the server-side rendering script (index.mjs or index-server.js).
Actual Behavior: When Vue components are bundled separately (using Webpack) and imported into the server-side code, the nested components do not render as expected. The output is missing the content of the child component (Test2Component), but the parent component (TestComponent) is rendered.
What is expected?
Expected Behavior:
The nested Vue component (e.g., TestComponent) should render correctly with its child components (e.g., Test2Component) when bundled separately.
What is actually happening?
When Vue components are bundled separately (using Webpack) and imported into the server-side code, the nested components do not render as expected. The output is missing the content of the child component (Test2Component), but the parent component (TestComponent) is rendered.
The child component is rendered as a empty comment.
Also getting the relevant errors (tested on separate setup)
[Vue warn]: resolveComponent can only be used in render() or setup().
[Vue warn]: Component <Anonymous> is missing template or render function.
System Info
node v20.16.0
Any additional comments?
An additional note is that the child component renders when using <script setup> Compositions API but not for <script> Options API as well.
I hope that it is not an issue with the webpack setup or configuration, any updates on this matter would be greatly appreciated.
The text was updated successfully, but these errors were encountered:
gerteck
changed the title
Nested Vue component does not render when bundled separately using Webpack
Nested Vue component does not render when bundled separately using Webpack for Options API
Feb 18, 2025
I don't think this is a bug in Vue Core, I think it's just a problem with the webpack config.
The warnings you're seeing typically indicate that there are two copies of Vue being used at runtime. The Vue application is using one copy of Vue but a component within it is using a different copy. As a result, functions like resolveComponent fail because they rely on global context variables being set, but those are set within the other copy of Vue. Other functions, like provide and inject, would fail in a similar manner if you were using them.
In the Composition API example you're importing Test2 directly, so it no longer relies on resolveComponent. That dodges the issue, but it isn't really fixing it, it's just luck that it isn't hitting any of the functions that would cause it to fail.
From a quick look through the files, it seems that dist/vue-components.bundle.js is really big, much bigger than it should be for the small components you've created. It looks like there's a copy of Vue being bundled into that file.
I haven't used webpack for a while, but I think you need to add Vue to the externals section of webpack-vue.config.js.
Vue version
3.5.13 (also tested on 3.3.11)
Link to minimal reproduction
https://github.com/gerteck/vue-render-bug
Steps to reproduce
webpack-vue.config.js
).index.mjs
orindex-server.js
).Actual Behavior: When Vue components are bundled separately (using Webpack) and imported into the server-side code, the nested components do not render as expected. The output is missing the content of the child component (Test2Component), but the parent component (TestComponent) is rendered.
What is expected?
Expected Behavior:
The nested Vue component (e.g.,
TestComponent
) should render correctly with its child components (e.g.,Test2Component
) when bundled separately.What is actually happening?
When Vue components are bundled separately (using Webpack) and imported into the server-side code, the nested components do not render as expected. The output is missing the content of the child component (
Test2Component
), but the parent component (TestComponent
) is rendered.The child component is rendered as a empty comment.
Also getting the relevant errors (tested on separate setup)
System Info
Any additional comments?
<script setup>
Compositions API but not for<script>
Options API as well.The text was updated successfully, but these errors were encountered: