【问题标题】:vue3+vite+vuei18n build "Uncaught TypeError: _ctx.$t is not a function"vue3+vite+vuei18n 构建“未捕获的类型错误:_ctx.$t 不是函数”
【发布时间】:2022-07-05 04:52:58
【问题描述】:

我想将我的 vue3+vite 包发布到 npm,但发布后,我在一个测试项目中遇到了“Uncaught TypeError: _ctx.$t is not a function”,我的包不工作,有什么建议...?

PS:我使用的是 vue options api

vite.configs.js:

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueI18n from '@intlify/vite-plugin-vue-i18n'

// https://vitejs.dev/config/
const path = require("path")
export default defineConfig({
  build: {
    lib: {
      entry: path.resolve(__dirname, 'src/install.ts'),
      name: 'vcp',
      fileName: (format) => `vcp.${format}.ts`
    },
    rollupOptions: {
      external: ['vue'],
      output: {
        exports: 'named',
        globals: {
          vue: 'Vue',
          vcp: 'Vcp'
        }
      }
    },
  },
  plugins: [
    vue(),
    vueI18n({
      include: path.resolve(__dirname, 'src/assets/translations.json'),
      compositionOnly: false,
    })
  ],
  server: {
    port: 8080
  },
  resolve: {
    dedupe: ['vue'],
    alias: {
      "~": path.resolve(__dirname, "./src"),
      "@": path.resolve(__dirname, "./src"),
    },
  },
})

【问题讨论】:

标签: vue.js vite vue-i18n


【解决方案1】:

我联系了 vue-i18n 所有者和owner of vue-i18n 他在this PR解决了我的问题

附注: 基本上,问题是vite i18n builder不支持ts格式。

【讨论】:

    猜你喜欢
    • 2021-08-17
    • 1970-01-01
    • 2023-02-21
    • 1970-01-01
    • 1970-01-01
    • 2023-02-08
    • 2017-08-02
    • 1970-01-01
    • 2022-11-19
    相关资源
    最近更新 更多