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

definePage fails with rsbuild #531

Open
gltjk opened this issue Oct 31, 2024 · 0 comments
Open

definePage fails with rsbuild #531

gltjk opened this issue Oct 31, 2024 · 0 comments

Comments

@gltjk
Copy link

gltjk commented Oct 31, 2024

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 About page screenshot

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant