微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ReferenceError: webpack_base_uri 未定义

如何解决ReferenceError: webpack_base_uri 未定义

错误


HTML Webpack 插件错误:webpack://webpack/data:text/javascript,webpack_public_path_=webpack_base_uri=_htmlWebpackPl uginPublicPath;?:2 webpack_require.p = webpack_base_uri = htmlWebpackPluginPublicPath; ^

ReferenceError:webpack_base_uri 未定义

  • javascript,webpack_public_path_=webpack_base_uri=htmlWebpackPluginPublicPath;?:2 eval webpack://webpack/data:text/javascript,webpack_public_path=webpack_base_uri=_htmlWebpackPluginP ublicPath;?:2:46

  • index.html:30 Object.data:text/javascript,webpack_public_path = webpack_base_uri = htmlWebpackPlug inPublicPath; C:/Users/Ymtx/Desktop/vue/webpack/src/index.html:30:1

  • index.html:53 webpack_require C:/Users/Ymtx/Desktop/vue/webpack/src/index.html:53:41


我不知道为什么会发生这种情况,我已经阅读了很多博客,但关于它的博客很少。我确实想用它来做。请帮助我。

代码

var webpack = require('webpack');

const path = require('path');

const HtmlWebpackPlugin = require('html-webpack-plugin');

const htmlPlugin = new HtmlWebpackPlugin({
    template:'./src/index.html',filename:'index.html',})

module.exports = {
mode:"development",entry:path.join(__dirname,'./src/index.js'),output:{
    path:path.join(__dirname,'./dist'),filename:'bundle.js'    
 },plugins:[htmlPlugin]

}

package.json

{
  "name": "webpack","version": "1.0.0","description": "","main": "index.js","scripts": {
    "test": "echo \"Error: no test specified\" && exit 1","dev": "webpack-dev-server --open --host --127.0.0.1 --port 8888"
  },"keywords": [],"author": "","license": "ISC","dependencies": {
    "jquery": "^3.6.0"
  },"devDependencies": {
    "css-loader": "^5.2.4","html-webpack-plugin": "^5.3.1","style-loader": "^2.0.0","vue": "^2.6.12","webpack": "^4.46.0","webpack-cli": "^3.3.12","webpack-dev-server": "^3.1.14"
  }
}

解决方法

尝试在 webpack 配置中添加插件:

plugins: [
    new webpack.DefinePlugin({
        'process.env.NODE_ENV': JSON.stringify('development')
    })
],

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。