首页 > 解决方案 > Uncaught ReferenceError: module is not defined at build.js:1 vuejs, webpack, SSR(我使用了 npm script-loader 但没用)

问题描述

集成 bundle.js 时出错,我使用了“script-loader”但没有用。使用 vuejs、vuex、ssr、vuetify、webpack.js 的库

错误:

  build.js:1 Uncaught ReferenceError: module is not defined
  at build.js:1 .   

标签: vue.jswebpackvuexvuetify.js

解决方案


更改脚本

  <script src="/dist/build.js"></script>

  <script nomodule src="/dist/build.js"></script>

在 script 标签中添加 nomodule 属性,这是因为我们在 webpack 配置中使用 libraryTarget: 'commonjs2'

最后我的 index.html 会像

<!doctype html>
 <html lang="en">
  <head>

  </head>
 <body>


   <script nomodule src="/dist/build.js"></script>


</body>
</html>

笔记:

do not make any changes in src attribute

推荐阅读