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

[Bug Report]: Failed to start if one of route is removed #1975

Open
fu050409 opened this issue Nov 29, 2024 · 2 comments
Open

[Bug Report]: Failed to start if one of route is removed #1975

fu050409 opened this issue Nov 29, 2024 · 2 comments
Labels
bug Something isn't working scope: cache

Comments

@fu050409
Copy link
Member

fu050409 commented Nov 29, 2024

Steps to reproduce

import {
  createRouter,
  createWebHashHistory,
  type RouteRecordRaw,
  type RouteComponent,
} from "vue-router";

const views: Record<string, { default: RouteComponent }> = import.meta.glob(
  ["./views/**/*.vue", "./views/**/index.vue", "./views/**/\\[*\\].vue"],
  {
    eager: true,
  }
);

const routes: RouteRecordRaw[] = Object.entries(views).map(
  ([filePath, component]) => {
    let path = filePath
      .replace(/^\.\/views\//, "")
      .replace(/\.vue$/, "")
      .replace(/^(.*)\/?index$/, "$1")
      .replace(/\[(\w+)\]$/, ":$1");
    path = "/" + path;

    return {
      path,
      name: filePath.replace(/^\.\/views\//, ""),
      component: component.default,
    } satisfies RouteRecordRaw;
  }
);

export default createRouter({
  history: createWebHashHistory(import.meta.env.BASE_URL),
  routes: [...routes],
});

Code above which stayed at src/router.ts can automatically load all routes from views directory, consider remove a .vue file from src/views

Reproduce link

No response

What is actually happening?

[ Farm ] Error: Failed to start the server
Caused by: Error: Can not resolve `./views/account/pro.vue` from src/router.ts.
Original error: None.

Potential Causes:
1.The file that `./views/account/pro.vue` points to does not exist.
2.Install it first if `./views/account/pro.vue` is an dependency from node_modules, if you are using pnpm refer to [https://pnpm.io/faq#pnpm-does-not-work-with-your-project-here] for solutions.
3. If `./views/account/pro.vue` is a alias, make sure your alias config is correct.

System Info

any
@fu050409
Copy link
Member Author

A workaround is to run pnpm farm clean to remove all cached files and restart the dev server.

@fu050409 fu050409 added bug Something isn't working scope: cache labels Nov 29, 2024
@wre232114
Copy link
Member

It's a bug, the module that uses import.meta.glob should not be cached.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working scope: cache
Projects
None yet
Development

No branches or pull requests

2 participants