webpack打包报错:if (!scriptUrl) throw new Error(“Automatic publicPath is not supported in this browser“)

2023-11-16

翻车现场

ERROR in Error: D:\Work\test\webpack-demo\05.打包图片资源\src\index.html:104
/******/ if (!scriptUrl) throw new Error(“Automatic publicPath is not supported in this browser”);
Error: Automatic publicPath is not supported in this browser
在这里插入图片描述

问题分析

是因为打包资源后不能解析“./”之类的路径,需要通过publicPath配置。

解决方案

在webpack.config.js的output配置中配置publicPath。如下:

module.exports = {
 	// 入口文件
    entry: "/src/index.js",
    output: {
        // 输出文件名
        filename: "bundle.js",
        // 输出路径,__dirname是当前文件的绝对路径,输出到绝对路径下的dist文件夹下
        path: resolve(__dirname, 'dist'),
        // 给打包后资源引入的路径前缀
        // 打包后路径公式:静态资源最终访问路径 = output.publicPath + 资源loader或插件等配置路径
        publicPath: "./"  // 这里不一定非要是'./',根据公式,自行配置
    },
}

如果对你有帮助,可以

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

webpack打包报错:if (!scriptUrl) throw new Error(“Automatic publicPath is not supported in this browser“) 的相关文章

随机推荐