学无先后,达者为师

网站首页 Vue 正文

module “**.vue“ has not default

作者:py_boy 更新时间: 2022-03-02 Vue

module “**.vue” has not default

这个问题造成的原因是因为你在vue.config.js中设置了happyPackMode选项,如下所示:

config.module
      .rule('ts')
      .use('ts-loader')
      .loader('ts-loader')
      .tap(options => {
        Object.assign(options || {}, {transpileOnly: false, happyPackMode: false, appendTsSuffixTo: [/\.vue$/]})
        return options
      })

把happyPackMode设置为true就好了
但是你一旦将happyPackMode设置为true你会发现你的vue3打成包后没有自动声明的文件

vue3.0打包自动生成声明文件

vue3.0打包没办法自动生成声明文件,必须将happyPackMode设置为false才可以
vue.config.js

config.module
      .rule('ts')
      .use('ts-loader')
      .loader('ts-loader')
      .tap(options => {
        Object.assign(options || {}, {transpileOnly: false, happyPackMode: false, appendTsSuffixTo: [/\.vue$/]})
        return options
      })

tsconfig.ts

"declaration": true,
 "declarationDir": "dist",
 "typeRoots": ["./src", "./node_modules/@types"],

二者冲突了怎么办呢

本人的解决方案如下:

// eslint-disable-next-line
// @ts-ignore
import example from './example/index.vue';

其实module “**.vue” has not default包错不会影响打包的效果,如果不想看到直接disabled,简单粗暴

其它

1.vue3项目使用子项目组件,提示子项目组件的setup为异步,我tm子项目组件的setup明明是同步啊,目前我的解决方案是打包后基于npm包引入的方式使用,有人知道原因可以评论告诉我。
2.vue3项目打包后,其它项目使用npm link引入发现声明文件没有生效,我的解决方式是将打包好的vue3项目先发布到npm仓库中,然后在其它项目中通过npm install的方式引入(这个时候发现声明文件生效了)。在vue3项目中使用npm build --watch --dest 其它项目/node_modules/****/dist命令,每次修改vue3项目时自动打包覆盖node_modules中的dist文件。

有人拥有更好的解决方案也可以评论告诉我。

原文链接:https://blog.csdn.net/py_boy/article/details/121511693

栏目分类
最近更新