5

I want to publish my vue3+vite package to npm but after publishing, I encountered "Uncaught TypeError: _ctx.$t is not a function" in a test project and my package is not working, any suggestions... ?

PS: I'm using 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"),
    },
  },
})
KiynL
  • 4,097
  • 2
  • 16
  • 34
Alireza Safari
  • 166
  • 2
  • 11
  • Take a look at this [link](https://github.com/intlify/vue-i18n-next/issues/350#issuecomment-782007971), It's because you are `$t` in your project. – Pouya M May 28 '22 at 12:09
  • My problem is with [vuei18n bundling tools for vite](https://github.com/intlify/bundle-tools/tree/main/packages/vite-plugin-vue-i18n) not the vuei18n itself, and globalInjection flag is for vuei18n – Alireza Safari May 29 '22 at 04:42

1 Answers1

1

I opened an issue and the owner of vue-i18n fixed my problem in this PR and here is the issue

P.S: basically, the problem was that vite i18n builder couldn't support ts format.

Alireza Safari
  • 166
  • 2
  • 11