vue3 vite打包部署后访问报错Expected a JavaScript module script but the server responded with a MIME type of

问题背景

  页面刷新后报错: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.

  问题原因:1、路径不对;2、Content-Type不对

  很明显路径上的dashboard就是多出来的一块、错误的路径。当我从根路径刷新favicon文件的第一次加载路径是对的,但如果我在dashboard这个路径下的某个文件执行刷新时,favicon就会报这个错误了。说明,他加载静态资源时,相对路径是上一级、而不是根路径导致的。

问题原因

  原因是加载不到静态资源,一般来说刷新就会有加载不到对应的资源问题的控制台报错

  解决:部署的时候要更改一下,即之前的 ./ 改为其他路径 或者/

  详见文档:https://cn.vitejs.dev/guide/build.html#public-base-path

posted @ 2018-03-16 20:36  古兰精  阅读(4474)  评论(0编辑  收藏  举报