vite项目打包nginx后在非根路径刷新页面会报Failed to load module script?

Failed to load module script: Expected a JavaScript module script but the server responded
with a MIME type of "text/html". Strict MIME type checking is enforced for module scripts
per HTML spec.export default defineConfig({
base: './',
minify: true在app.xxxx.cn路径下刷新就没有问题,在https://app.xxx.cn/me/userinfo这样非根路径刷新页面就报如上图的错误?
回复
1个回答
test
2024-06-29
你这个图,看网络请求记录,应该会有一些404的错误请求记录,点看就能看到具体的请求路径了。
根据具体路径再去排查:
- base是否配置好,根据编译后的
index.html里去确认,看看引入的script的src是否是./开头 - 是否发布成功到服务器
- 看你链接没有
#,Nginx要配置rewrite - 如果链接使用
#号的格式,结尾应该是/#/或者/index.html#/
回复
适合作为回答的
- 经过验证的有效解决办法
- 自己的经验指引,对解决问题有帮助
- 遵循 Markdown 语法排版,代码语义正确
不该作为回答的
- 询问内容细节或回复楼层
- 与题目无关的内容
- “赞”“顶”“同问”“看手册”“解决了没”等毫无意义的内容