Description
Hi, I just moved one of my vite project to rsbuild and found meta information given by definePage
disappeared.
Here is a demo project: https://github.com/gltjk/rsbuild-unplugin-vue-router
I used definePage
in src/pages/index.vue
:
<script setup>
definePage({
meta: {
title: 'Home',
},
});
</script>
and in src/pages/about.vue
<script setup>
definePage({
meta: {
title: 'About',
},
});
</script>
I also rendered the whole route
object on the page. Here are the screenshots of those two pages, where it is clearly seen that the meta
object is empty.
![Home page screenshot](https://private-user-images.githubusercontent.com/1887124/381794813-83ab9191-8fb7-4b91-94bd-89eb219bbc5f.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzg5MzcyMjYsIm5iZiI6MTczODkzNjkyNiwicGF0aCI6Ii8xODg3MTI0LzM4MTc5NDgxMy04M2FiOTE5MS04ZmI3LTRiOTEtOTRiZC04OWViMjE5YmJjNWYucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIwNyUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMDdUMTQwMjA2WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9YzBjNDczZDBlNDkwN2YyN2EyN2NlNThiNWQzYjhiNjdhNGI3NDdmM2M4YzVlNWYwZTFlMzc5ODQ2OTIwYWZmOSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.2-QOsXSPwLNAF-Rs0C-a1i1U5z2S4NQE_TumfH2hSAE)
![About page screenshot](https://private-user-images.githubusercontent.com/1887124/381794840-4eca7bd0-d738-43b8-9813-d1e079d4b4c6.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzg5MzcyMjYsIm5iZiI6MTczODkzNjkyNiwicGF0aCI6Ii8xODg3MTI0LzM4MTc5NDg0MC00ZWNhN2JkMC1kNzM4LTQzYjgtOTgxMy1kMWUwNzlkNGI0YzYucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIwNyUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMDdUMTQwMjA2WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9YzAzOTczMTk2ODQ2OTBkZGVkMjIwYjkxZDllNGVmMjMzMDJjY2QwN2U4NzFlMDU3NDc2YjI5MTg4MGYxNzdlMyZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.F0BOF8w8a2XvrMGEWZXFw9CMPkFZf0AQu2a4U7t-rPA)
There is also an error shown in the terminal when the project starts. Here is it:
error Compile error:
Failed to compile, check the errors for troubleshooting.
File: /Users/username/project-path/rsbuild-vue/src/pages/about.vue?definePage&vue&lang.tsx:1:1
× ModuleError: At least one <template> or <script> is required in a single file component. /Users/username/project-path/rsbuild-vue/src/pages/about.vue (from: /Users/username/project-path/rsbuild-vue/node_modules/vue-loader/dist/index.js??ruleSet[0].use[0])
│ at parse$1 (/Users/username/project-path/rsbuild-vue/node_modules/@vue/compiler-sfc/dist/compiler-sfc.cjs.js:1864:7)
│ at Object.loader (/Users/username/project-path/rsbuild-vue/node_modules/vue-loader/dist/index.js:64:36)
│ at LOADER_EXECUTION (/Users/username/project-path/rsbuild-vue/node_modules/@rspack/core/dist/index.js:10363:18)
│ at runSyncOrAsync2 (/Users/username/project-path/rsbuild-vue/node_modules/@rspack/core/dist/index.js:10364:6)
│ at node:internal/util:433:21
│ at new Promise (<anonymous>)
│ at runSyncOrAsync2 (node:internal/util:419:12)
│ at runLoaders (/Users/username/project-path/rsbuild-vue/node_modules/@rspack/core/dist/index.js:10833:54)
File: /Users/username/project-path/rsbuild-vue/src/pages/index.vue?definePage&vue&lang.tsx:1:1
× ModuleError: At least one <template> or <script> is required in a single file component. /Users/username/project-path/rsbuild-vue/src/pages/index.vue (from: /Users/username/project-path/rsbuild-vue/node_modules/vue-loader/dist/index.js??ruleSet[0].use[0])
│ at parse$1 (/Users/username/project-path/rsbuild-vue/node_modules/@vue/compiler-sfc/dist/compiler-sfc.cjs.js:1864:7)
│ at Object.loader (/Users/username/project-path/rsbuild-vue/node_modules/vue-loader/dist/index.js:64:36)
│ at LOADER_EXECUTION (/Users/username/project-path/rsbuild-vue/node_modules/@rspack/core/dist/index.js:10363:18)
│ at runSyncOrAsync2 (/Users/username/project-path/rsbuild-vue/node_modules/@rspack/core/dist/index.js:10364:6)
│ at node:internal/util:433:21
│ at new Promise (<anonymous>)
│ at runSyncOrAsync2 (node:internal/util:419:12)
│ at runLoaders (/Users/username/project-path/rsbuild-vue/node_modules/@rspack/core/dist/index.js:10833:54)
It seems that the definePage
part is rendered as a separate SFC rather than part of the original vue file.
Here is my rsbuild.config.mjs
for reference:
import { defineConfig } from '@rsbuild/core';
import { pluginVue } from '@rsbuild/plugin-vue';
import { rspack as VueRouter } from 'unplugin-vue-router';
export default defineConfig({
plugins: [pluginVue()],
tools: {
rspack: {
plugins: [VueRouter()],
},
},
});
For other information please refer to the repository I posted above or feel free to discuss here.
I'm not sure why this happened and am hoping for assistance. Thanks!