目 录CONTENT

文章目录

MIME type of text/html

xlong
2024-04-10 / 0 评论 / 0 点赞 / 11 阅读 / 1521 字 / 正在检测是否收录...

MIME type of "text/html"

网页打开显示空白,打开F12的console页面发现下面的错误:

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. 

错误原因: 该错误是因为使用vue代码配置history路由模式由yarn编译成静态代码供nginx代理,配置二级路径访问时报的错。

解决方法:

1.首先查看console页面所以的请求是否全部带上二级路径。

2.如果所有路径都配置正确,查看vue代码是否配置二级路径。 在 vite.config.js指定 base 属性为 /show/;/show/为二级路径

3.查看nginx配置,是否配置转发 需配置下面location /market/和location /配置。

cat >default.conf<<'EOF'
server {
    listen                      80 reuseport;
    server_name                 localhost;
...
    location /show/ {
        proxy_pass              http://localhost/;
    }

    location / {
        try_files $uri $uri/ /index.html;
    }
}
EOF

0

评论区