Daydreamer-riri / vite-react-ssg

Static-site generation for React on Vite.
https://vite-react-ssg.netlify.app/
MIT License
123 stars 6 forks source link

vite-react-ssg与antd-mobile存在冲突对于 require("./global.css");的引用报错 #36

Open changekey opened 1 month ago

changekey commented 1 month ago

[vite] Error when evaluating SSR module C:/Users/46848/Desktop/project/converting-mobile/src/main.tsx: failed to import "antd-mobile" |- C:\Users\46848\Desktop\project\converting-mobile\node_modules\antd-mobile\cjs\global\global.css:1 :root { ^

SyntaxError: Unexpected token ':' at internalCompileFunction (node:internal/vm:76:18) at wrapSafe (node:internal/modules/cjs/loader:1283:20) at Module._compile (node:internal/modules/cjs/loader:1328:27) at Module._extensions..js (node:internal/modules/cjs/loader:1422:10) at Module.load (node:internal/modules/cjs/loader:1203:32) at Module._load (node:internal/modules/cjs/loader:1019:12) at Module.require (node:internal/modules/cjs/loader:1231:19) at require (node:internal/modules/helpers:177:18) at Object. (C:\Users\46848\Desktop\project\converting-mobile\node_modules\antd-mobile\cjs\global\index.js:3:1) at Module._compile (node:internal/modules/cjs/loader:1364:14) 会出现无法引用的报错 当前采用的形式,使用 //router/router import {createBrowserRouter } from "react-router-dom"; const routers = createBrowserRouter([ { path: "/", element: ( ), },]); export default routers; //main.tsx import { ViteReactSSG } from "vite-react-ssg"; import routers from "@/router/router"; export const createRoot = ViteReactSSG({ routes: routers.routes }); 会出现以上报错

Daydreamer-riri commented 1 month ago

麻烦提供一个可以复现错误的仓库吧,这可以帮助我更好的定位问题。

changekey commented 1 month ago

https://github.com/changekey/vite-base.git,仓库已经创建号了,虽然报错不一样的,但是都是因为其他组件库中使用require("./global.css")来引入css,文件而产生的报错

Daydreamer-riri commented 1 month ago

Hi @changekey,这个仓库不是最小复现仓库,目前有许多其他问题会导致服务端渲染失败,比如在服务端直接访问了 windowdocument,在服务端使用了 createHashRouter 等。麻烦再创建一个最小复现仓库吧,辛苦。