uni-app配置了H5的发布后,再在浏览器上运行就报错

uni-app配置了H5的发布后,再在浏览器上运行就报错

配置了H5的发布后,再在浏览器上运行就报错,提示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.
[HMR] Waiting for update signal from WDS...

如果把h5的发布配置删掉就又正常,主要是h5也没配置什么内容

![https://www.itying.com/uniimg.php?url=https://img-cdn-tc.dcloud.net.cn/uploads/questions/20211112/822bdf4ce1109c038eabe5050e2421b6.png](https://www.itying.com/uniimg.php?url=https://img-cdn-tc.dcloud.net.cn/uploads/questions/20211112/822bdf4ce1109c038eabe5050e2421b6.png)

![https://www.itying.com/uniimg.php?url=https://img-cdn-tc.dcloud.net.cn/uploads/questions/20211112/1172d4d80ff91eb29f467c692168b021.png](https://www.itying.com/uniimg.php?url=https://img-cdn-tc.dcloud.net.cn/uploads/questions/20211112/1172d4d80ff91eb29f467c692168b021.png)

更多关于uni-app配置了H5的发布后,再在浏览器上运行就报错的实战教程也可以访问 https://www.itying.com/category-93-b0.html

3 回复

你打包路径是不是’./‘ 改成’/‘就ok了,我这是这样弄好的,,,,

更多关于uni-app配置了H5的发布后,再在浏览器上运行就报错的实战教程也可以访问 https://www.itying.com/category-93-b0.html


是要看看路径,因为你部署的文件夹位置可能和域名指向目录存在层级关系

这个错误是由于H5发布配置中的publicPath设置不当导致的。当配置了H5的publicPath后,开发服务器在加载模块时路径解析错误,返回了HTML页面而不是JavaScript模块,从而触发MIME类型检查失败。

从你提供的配置截图来看,publicPath设置为./,这在某些服务器环境下可能导致路径问题。以下是解决方案:

  1. 临时解决方案

    • 在开发阶段,可以暂时删除publicPath配置,或将其设置为空字符串''
    • 或者使用完整路径:publicPath: '/'
  2. 根本解决方案

    // manifest.json 或 vue.config.js
    "h5": {
      "publicPath": process.env.NODE_ENV === 'production' ? './' : '/'
    }
回到顶部