首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >ReferenceError:未定义webpack_base_uri

ReferenceError:未定义webpack_base_uri
EN

Stack Overflow用户
提问于 2021-04-27 12:03:30
回答 2查看 1.5K关注 0票数 2

错误:

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

ReferenceError: webpack_base_uri未定义为

webpack_public_path_=webpack_base_uri=htmlWebpackPluginPublicPath;?:2

  • javascript,__webpack_public_path=webpack_base_uri=_htmlWebpackPluginP ublicPath;?:2:46

  • javascript

  • 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

我不知道为什么会发生这种事,我也读过很多博客,但是很少有关于它的博客,我确实想用it.Please来帮助我。

代码↓

代码语言:javascript
运行
复制
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

代码语言:javascript
运行
复制
{
  "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"
  }
}
EN

回答 2

Stack Overflow用户

发布于 2021-10-31 11:43:53

这个问题是因为html-webpack-plugin,它目前要求一个对等的"webpack": "^5.20.0",但是__webpack_base_uri__是在5.21.0中添加的。

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

要快速修复,您可以将您的webpack.config.js放在__webpack_base_uri__ = 'http://localhost:8081';顶部

Nota:端口是提供devServer的地方

票数 3
EN

Stack Overflow用户

发布于 2021-04-27 12:14:45

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

代码语言:javascript
运行
复制
plugins: [
    new webpack.DefinePlugin({
        'process.env.NODE_ENV': JSON.stringify('development')
    })
],
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67282705

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档