Vue3.x Error:vue__WEBPACK_IMPORTED_MODULE_0__.createElementBlock

2021-12-08 15:28:54 浏览数 (1)

Vue3.x错误:vue__WEBPACK_IMPORTED_MODULE_0__.createElementBlock

见错误信息:

代码语言:javascript复制
index.vue:2 Uncaught TypeError: (0 , vue__WEBPACK_IMPORTED_MODULE_0__.createElementBlock) is not a function
    at Proxy.render (index.vue:2)
    at $n (vue.global.js:2422)
    at vue.global.js:6415
    at n (vue.global.js:410)
    at ie (vue.global.js:385)
    at B (vue.global.js:6368)
    at j (vue.global.js:6327)
    at P (vue.global.js:6285)
    at g (vue.global.js:5890)
    at oe (vue.global.js:7005)

如图所示:

解决方案:

经过资料查询,网上提供有相对应的解决方案,如下:

代码语言:javascript复制
rm -rf node_modules/
rm package-lock.json
npm cache verify
npm i && npm up
//资料来源:https://stackoverflow.com/questions/68795955/vue-3-package-update-errors

但(总有个但是),你发现使用上述步骤之后还是有问题,那么,你是不是使用了webpack.externals

需要修改,templates/index.html 文件 <script> 的引用,如下:

代码语言:javascript复制
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
  <title><%= htmlWebpackPlugin.options.title %></title>
  
  <!--要修改引用版本号-->
  <script src="https://cdn.jsdelivr.net/npm/vue@3.2.7/dist/vue.global.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/vue-router@4.0.11/dist/vue-router.global.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/vuex@4.0.2/dist/vuex.global.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/axios@0.21.0/dist/axios.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/vue-i18n@9.2.0-beta.3/dist/vue-i18n.global.min.js"></script>

</head>

<body>
  <div id="app"></div>
</body>

</html>```

0 人点赞