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

LoadingComponent path error #5

Closed
nmezhangxi opened this issue Jan 6, 2022 · 3 comments
Closed

LoadingComponent path error #5

nmezhangxi opened this issue Jan 6, 2022 · 3 comments
Labels
bug Something isn't working

Comments

@nmezhangxi
Copy link

nmezhangxi commented Jan 6, 2022

[vite] Internal server error: Failed to resolve import "C:UserszhangDesktop
ite-reactsrccomponentsPageLoading" from "src\.vit\routes.ts". Does the file exist?
  Plugin: vite:import-analysis
  File: C:/Users/zhang/Desktop/vite-react/src/.vit/routes.ts
  4  |  import BulbOutlined from "@ant-design/icons/BulbOutlined";
  5  |  import UserOutlined from "@ant-design/icons/UserOutlined";
  6  |  import LoadingComponent from "C:UserszhangDesktop\vite-reactsrccomponentsPageLoading";
     |                                ^
  7  |  export default function getRoutes() {
  8  |    const routes = [{
      at formatError (C:\Users\zhang\Desktop\vite-react\node_modules\vite\dist\node\chunks\dep-76613303.js:36769:46)
      at TransformContext.error (C:\Users\zhang\Desktop\vite-react\node_modules\vite\dist\node\chunks\dep-76613303.js:36765:19)
      at normalizeUrl (C:\Users\zhang\Desktop\vite-react\node_modules\vite\dist\node\chunks\dep-76613303.js:73686:26)
      at processTicksAndRejections (node:internal/process/task_queues:96:5)
      at async TransformContext.transform (C:\Users\zhang\Desktop\vite-react\node_modules\vite\dist\node\chunks\dep-76613303.js:73826:57)
      at async Object.transform (C:\Users\zhang\Desktop\vite-react\node_modules\vite\dist\node\chunks\dep-76613303.js:36985:30)
      at async doTransform (C:\Users\zhang\Desktop\vite-react\node_modules\vite\dist\node\chunks\dep-76613303.js:52049:29)
@nmezhangxi
Copy link
Author

nmezhangxi commented Jan 6, 2022

vit路径下的routes文件中实际是以下内容

// @ts-nocheck
import { dynamic } from '@vitjs/runtime';
import React from 'react';
import SmileOutlined from '@ant-design/icons/SmileOutlined'
import BulbOutlined from '@ant-design/icons/BulbOutlined'
import UserOutlined from '@ant-design/icons/UserOutlined'

import LoadingComponent from 'C:\Users\zhang\Desktop\vite-react\src\components\PageLoading';

export default function getRoutes() {
  const routes = [
  {
    "path": "/",
    "component": dynamic({ loader: () => import('C:\\Users\\zhang\\Desktop\\vite-react\\src\\layouts\\BlankLayout'), loading: LoadingComponent}),
    "routes": [
      {
        "path": "/user",
        "component": dynamic({ loader: () => import('C:\\Users\\zhang\\Desktop\\vite-react\\src\\layouts\\UserLayout'), loading: LoadingComponent}),
        "routes": [
          {
            "name": "登录",
            "path": "/user/login",
            "component": dynamic({ loader: () => import('C:\\Users\\zhang\\Desktop\\vite-react\\src\\pages\\User\\Login'), loading: LoadingComponent}),
            "exact": true
          }
        ]
      },
      {
        "path": "/",
        "component": dynamic({ loader: () => import('C:\\Users\\zhang\\Desktop\\vite-react\\src\\layouts\\SecurityLayout'), loading: LoadingComponent}),
        "routes": [
          {
            "path": "/",
            "component": dynamic({ loader: () => import('C:\\Users\\zhang\\Desktop\\vite-react\\src\\layouts\\BasicLayout'), loading: LoadingComponent}),
            "routes": [
              {
                "path": "/",
                "redirect": "/welcome",
                "exact": true
              },
              {
                "path": "/welcome",
                "icon": React.createElement(SmileOutlined),
                "name": "欢迎页",
                "component": dynamic({ loader: () => import('C:\\Users\\zhang\\Desktop\\vite-react\\src\\pages\\Welcome'), loading: LoadingComponent}),
                "exact": true
              },
              {
                "path": "/concent",
                "icon": React.createElement(BulbOutlined),
                "name": "Concent Demo",
                "routes": [
                  {
                    "path": "/concent/hello-world",
                    "name": "Hello World",
                    "component": dynamic({ loader: () => import('C:\\Users\\zhang\\Desktop\\vite-react\\src\\pages\\Concent\\HelloWorld'), loading: LoadingComponent}),
                    "exact": true
                  }
                ]
              },
              {
                "path": "/account",
                "icon": React.createElement(UserOutlined),
                "name": "个人页",
                "routes": [
                  {
                    "path": "/account/center",
                    "name": "个人中心",
                    "component": dynamic({ loader: () => import('C:\\Users\\zhang\\Desktop\\vite-react\\src\\pages\\Account\\Center'), loading: LoadingComponent}),
                    "exact": true
                  },
                  {
                    "path": "/account/settings",
                    "name": "个人设置",
                    "component": dynamic({ loader: () => import('C:\\Users\\zhang\\Desktop\\vite-react\\src\\pages\\Account\\Settings'), loading: LoadingComponent}),
                    "exact": true
                  }
                ]
              }
            ]
          },
          {
            "component": dynamic({ loader: () => import('C:\\Users\\zhang\\Desktop\\vite-react\\src\\pages\\404'), loading: LoadingComponent}),
            "exact": true
          }
        ]
      },
      {
        "component": dynamic({ loader: () => import('C:\\Users\\zhang\\Desktop\\vite-react\\src\\pages\\404'), loading: LoadingComponent}),
        "exact": true
      }
    ]
  },
  {
    "component": dynamic({ loader: () => import('C:\\Users\\zhang\\Desktop\\vite-react\\src\\pages\\404'), loading: LoadingComponent}),
    "exact": true
  }
];
  return routes;
}

@yunsii
Copy link
Owner

yunsii commented Jan 6, 2022

感谢反馈,应该是 Windows 下生成组件路径没处理导致的,源码看这里 https://github.com/vitjs/vit/blob/b4fdc68ed00da3d47e441440ab487db60df120b3/packages/vit/src/generateFiles/routes.ts#L49

争取尽快处理,Windows 下的话可以选择暂时先不用代码分割,抑或 PR 一下 😄

@yunsii yunsii added the bug Something isn't working label Jan 6, 2022
@yunsii
Copy link
Owner

yunsii commented Jan 10, 2022

vitjs/vit@508fc90

已修复,在项目内更新 @vitjs 相关依赖即可 yarn upgrade --scope @vitjs

@yunsii yunsii closed this as completed Jan 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants