ReferenceError: webpack_base_uri is not defined

2.1k views Asked by At

ERROR:


Html Webpack Plugin: Error: 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 is not defined

  • 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


I didn't know why it was happended,and i have read many blog,but there were few blog about it.I do want to do with it.Please help me.

code ↓

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"
  }
}
2

There are 2 answers

2
Hem Joshi On

Try to add plugin in webpack config:

plugins: [
    new webpack.DefinePlugin({
        'process.env.NODE_ENV': JSON.stringify('development')
    })
],
0
Armando Júnior On

This issue is because of html-webpack-plugin it currently asks for a peer of "webpack": "^5.20.0" but __webpack_base_uri__ was added in 5.21.0.

https://webpack.js.org/api/module-variables/#__webpack_base_uri__-webpack-specific

To quick fix you can put into your webpack.config.js on the top __webpack_base_uri__ = 'http://localhost:8081';

Nota: the port is where your devServer will be provided