intlify / vue-i18n

Vue I18n for Vue 3
https://vue-i18n.intlify.dev/
MIT License
2.03k stars 323 forks source link

TypeError: o is not a function #747

Closed zeyadsharo closed 2 years ago

zeyadsharo commented 2 years ago

@kazupon @jiaozhiye @VanishMax

I have the same problem at the production level only there is no error for the dev level

 System:
    OS: Windows 10 10.0.19042
    CPU: (8) x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
    Memory: 6.37 GB / 15.92 GB
  Binaries:
    Node: 15.8.0 - C:\Program Files\nodejs\node.EXE
    npm: 7.24.1 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.19041.1266.0), Chromium (94.0.992.50)
    Internet Explorer: 11.0.19041.1202

packages
"@asigloo/vue-dynamic-forms": "^3.16.3",
    "@fortawesome/fontawesome-svg-core": "^1.2.35",
    "@fortawesome/free-solid-svg-icons": "^5.15.3",
    "@fortawesome/vue-fontawesome": "^3.0.0-4",
    "@hennge/vue3-pagination": "^1.0.17",
    "@popperjs/core": "^2.10.1",
    "@vueform/multiselect": "^2.2.0",
    "@vueuse/core": "^6.4.1",
    "@vueuse/integrations": "^6.3.2",
    "core-js": "^3.18.0",
    "cors": "^2.8.5",
    "dayjs": "^1.10.7",
    "express": "^4.17.1",
    "litepie-datepicker": "^1.0.14",
    "primeicons": "^4.1.0",
    "primevue": "^3.7.1",
    "router-link": "0.0.4",
    "vue-draggable-next": "^2.0.1",
    "serve-static": "^1.14.1",
    "vee-validate": "^4.4.11",
    "vue": "^3.2.11",
    "vue-i18n": "^9.1.9",
    "vue-loading-overlay": "^4.0.4",
    "vue-multiselect": "^3.0.0-alpha.2",
    "vue-next-select": "^2.10.1",
    "vue-router": "^4.0.10",
    "vue-search-select": "^2.9.4",
    "vue-sidebar-menu": "^5.0.0-alpha.9",
    "vue-simple-search-dropdown": "^1.0.1",
    "vue-sweetalert2": "^5.0.2",
    "vue-tailwind-picker": "^2.0.0",
    "vue-toastification": "^2.0.0-rc.1",
    "vue-upload-drop-images": "^1.0.7",
    "vue3-table-lite": "^1.0.6",
    "vue3-tailwind-datepicker": "^1.0.16",
    "vuex": "^4.0.2",
    "yup": "^0.32.9"

config I18n

const i18n = createI18n(
    {
        globalInjection: true,
        legacy: false,
        inheritLocale: true,
        locale: localStorage.getItem('locale'),
        availableLocales: ['ar', 'en', 'ku'],
        messages: {
            en: en,
            ar: ar,
            ku: ku
        },
    }
)
app.use(i18n)

error

image

code

<template>
    <div class="flex">
      <!-- Backdrop -->
      <div
          :class="isOpen ? 'block' : 'hidden'"
          class="fixed z-20 inset-0 bg-black opacity-50 transition-opacity lg:hidden"
          @click="isOpen = false"
      ></div>
      <div
          :class="isOpen ? 'translate-x-0 ease-out' : '-translate-x-full ease-in'"
          class="fixed z-30 inset-y-0 left-0 w-50 transition duration-300 transform bg-gray-900 overflow-y-auto lg:translate-x-0 lg:static lg:inset-0"
      >
        <!-- Logo Link -->
        <router-link to="/dashboard">
          <div class="flex items-center justify-start mt-8">
            <div class="flex items-center">
              <svg
                  class="h-12 w-12"
                  fill="none"
                  viewBox="0 0 512 512"
                  xmlns="http://www.w3.org/2000/svg"
              >
                <path
                    d="M364.61 390.213C304.625 450.196 207.37 450.196 147.386 390.213C117.394 360.22 102.398 320.911 102.398 281.6C102.398 242.291 117.394 202.981 147.386 172.989C147.386 230.4 153.6 281.6 230.4 307.2C230.4 256 256 102.4 294.4 76.7999C320 128 334.618 142.997 364.608 172.989C394.601 202.981 409.597 242.291 409.597 281.6C409.597 320.911 394.601 360.22 364.61 390.213Z"
                    fill="#4C51BF"
                    stroke="#4C51BF"
                    stroke-linecap="round"
                    stroke-linejoin="round"
                    stroke-width="2"
                />
                <path
                    d="M201.694 387.105C231.686 417.098 280.312 417.098 310.305 387.105C325.301 372.109 332.8 352.456 332.8 332.8C332.8 313.144 325.301 293.491 310.305 278.495C295.309 263.498 288 256 275.2 230.4C256 243.2 243.201 320 243.201 345.6C201.694 345.6 179.2 332.8 179.2 332.8C179.2 352.456 186.698 372.109 201.694 387.105Z"
                    fill="white"
                />
              </svg>

              <span class="text-white text-2xl mx-2 font-semibold"
              >{{ $t('pos') }}</span
              >
            </div>
          </div>
        </router-link>
      </div>
    </div>
</template>

<script lang="ts" setup>
import {ref} from "vue";
import {useSidebar} from "/src/hooks/useSidebar";
const {isOpen} = useSidebar();
const activeClass = ref(
    "bg-gray-600 bg-opacity-25 text-gray-100 border-gray-100"
);
const inactiveClass = ref(
    "border-gray-900 text-gray-500 hover:bg-gray-600 hover:bg-opacity-25 hover:text-gray-100"
)
</script>

Vite config

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

export default defineConfig({
    devServer: {
        watchOptions: {
            poll: true,
        },
    },
    define: {
        'process.env': process.env
    },
    plugins: [
        vue(), // you need to install `@vitejs/plugin-vue`
        vueI18n({
            // if you want to use Vue I18n Legacy API, you need to set `compositionOnly: false`
            // compositionOnly: false,

            // you need to set i18n resource including paths !
            include: path.resolve(__dirname, './path/to/src/locales/**')
        })
    ],
    resolve: {
        alias: {
            '@': path.resolve(__dirname, '/src'),
            'vue-i18n': 'vue-i18n/dist/vue-i18n.cjs.js' //解决警告You are running the esm-bundler build of vue-i18n. It is recommended to configure your bundler to explicitly replace feature flag globals with boolean literals to get proper tree-shaking in the final bundle.
            , 'vue': 'vue/dist/vue.esm-bundler.js'
        },
    },
    server: {
        hmr: {
            protocol: 'ws',
            host: 'localhost',
            overlay: false
        },
        open: true,
    },
})

src Folder structure

image

Originally posted by @zeyadsharo in https://github.com/intlify/vue-i18n-next/issues/746#issuecomment-944892389

kazupon commented 2 years ago

Thank you for your reporting!

Sorry, I’m late due to my day job and family matters :disappointed: Please wait ... :pray:

RollingTL commented 2 years ago

Hi, I have the same problem! All worked nice untill I had don - "npm update" a day ago! In production I have following error: vendor.a81a33b9.js:1 TypeError: a is not a function at Uh (vendor.a81a33b9.js:5) at Gh (vendor.a81a33b9.js:5) at vendor.a81a33b9.js:5 at M (vendor.a81a33b9.js:5) at Proxy.A (vendor.a81a33b9.js:5) at index.2162502b.js:1 at Object.r [as default] (vendor.a81a33b9.js:1) at Proxy. (vendor.a81a33b9.js:1) at tl (vendor.a81a33b9.js:1) at Ys.U [as fn] (vendor.a81a33b9.js:1)

But I also have errors in dev mode: vue-i18n.runtime.esm-browser.prod.js:6 Uncaught (in promise) TypeError: o is not a function at me (vue-i18n.runtime.esm-browser.prod.js:6) at ue (vue-i18n.runtime.esm-browser.prod.js:6) at vue-i18n.runtime.esm-browser.prod.js:6 at H2 (vue-i18n.runtime.esm-browser.prod.js:6) at Proxy.V2 (vue-i18n.runtime.esm-browser.prod.js:6) at TopBar.vue:77 at Proxy.renderFnWithContext (runtime-core.esm-bundler.js:401) at Proxy. (runtime-core.esm-bundler.js:1236) at renderComponentRoot (runtime-core.esm-bundler.js:444) at ReactiveEffect.componentUpdateFn [as fn] (runtime-core.esm-bundler.js:4279)

Dear Kazupon fix this problem ASAP.

ghost commented 2 years ago

Same error : )

vue-i18n.runtime.esm-browser.prod.js:6 Uncaught (in promise) TypeError: o is not a function
    at me (vue-i18n.runtime.esm-browser.prod.js:6)
    at ue (vue-i18n.runtime.esm-browser.prod.js:6)
    at vue-i18n.runtime.esm-browser.prod.js:6
    at H2 (vue-i18n.runtime.esm-browser.prod.js:6)
    at Proxy.V2 (vue-i18n.runtime.esm-browser.prod.js:6)
    at Proxy._sfc_render (Markets.vue:29)
    at renderComponentRoot (runtime-core.esm-bundler.js:424)
    at ReactiveEffect.componentUpdateFn [as fn] (runtime-core.esm-bundler.js:4189)
    at ReactiveEffect.run (reactivity.esm-bundler.js:160)
    at setupRenderEffect (runtime-core.esm-bundler.js:4315)
ghost commented 2 years ago

Quick fix: use v9.1.9

kazupon commented 2 years ago

I've just released out v9.2.0-beta.13 https://github.com/intlify/vue-i18n-next/releases/tag/v9.2.0-beta.13

Please try it!

TechWatching commented 2 years ago

I still have this error when using script setup with vue-i18n. @kazupon should the translation be outside of setup, in a mounted or something like that ?

ZuulAndRibbon commented 2 years ago

I still have the same error.I have update vue-i18n to v9.2.0-beta.13 . pls help me @kazupon

Please try it!

DevIsShortForDevil commented 2 years ago

I also kinda have the same problem, but I get "a is not a function" in production. , tried both v9.1.9 and v9.2.0-beta.13 with no luck. It was fine maybe a month ago but now I can't release any updates because of this. @kazupon , can you help me please ?

ZuulAndRibbon commented 2 years ago

I also kinda have the same problem, but I get "a is not a function" in production. , tried both v9.1.9 and v9.2.0-beta.13 with no luck. It was fine maybe a month ago but now I can't release any updates because of this. @kazupon , can you help me please ?

I have the same error in production but there is no problem in development.Finally,I remove vite-i18n-plugin(I forget the name) and only use i18n and solve it

ogensec commented 2 years ago

Same problem here: o is not a function in production. No error in development.

ogensec commented 2 years ago

Resolved with : runtimeOnly: false

image

mxcd commented 2 years ago

@0G3NS3C Works for me. Just out of curiosity: why? What does this flag change