question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: _normalize is not a function

See original GitHub issue

Reporting a bug?

I’m migrating a Vue2 project from Webpack to Vite. We have been using vue-i18n extensively. We have a special folder structure, so after importing all translation files as modules with Vite’s globEager, I am creating a messages object that should be used throughout the app (and it is the same structure that we have successfully used w/ Webpack). However, the translation strings in my object come back as a function, such as: title: (ctx) => {const { normalize: _normalize } = ctx;return _normalize(["My Translated Title"])} When I’m trying to use i18n in a component, I get the below message: TypeError: _normalize is not a function (and my component won’t render).

Expected behavior

The above error message should not happen, component with vue-i18n based translation should render seamlessly.

Reproduction

Here’s a link to a minimal reproducible example in codesandbox: https://codesandbox.io/s/mre-vue-i18n-normalize-is-not-a-function-duuxwt

i18n.js:

import Vue from 'vue'
import VueI18n from 'vue-i18n'
import messages from '@intlify/vite-plugin-vue-i18n/messages'

//...

export default new VueI18n({
  locale: import.meta.VITE_I18N_LOCALE || locale,
  fallbackLocale: import.meta.VITE_I18N_FALLBACK_LOCALE || locale,
  messages: getLocaleMessages() // this returns custom messages object
})

vite.config.js

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

export default defineConfig({
  define: {
    'process.env': {}
  },
  plugins: [
    vue(),
    vueI18n({
      compositionOnly: false, // set this to false to use Vue I18n Legacy API
      include: path.resolve(__dirname, './src/locales/**')
    })
  ],
  resolve: {
    alias: {
      "@": path.resolve(__dirname, "./src")
    }
  }
})

System Info

System:
    OS: Windows 10 10.0.19044
    CPU: (8) x64 Intel(R) Core(TM) i5-8265U CPU @ 1.60GHz    
    Memory: 2.28 GB / 15.77 GB
  Binaries:
    Node: 12.14.1 - C:\Program Files\nodejs\node.EXE
    npm: 6.13.4 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Chrome: 100.0.4896.127
    Edge: Spartan (44.19041.1266.0), Chromium (100.0.1185.44)
    Internet Explorer: 11.0.19041.1566

Screenshot

image

Additional context

No response

Validations

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:3
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
Adnan-kreikercommented, Nov 25, 2022

I’m also migrating a vue 2.7 app from webpack to vite.

I Have been stuck on this error for hours 😕. Any update? I followed the migration guide without success.

I’m still getting TypeError: _normalize is not a function

1reaction
pedrolamascommented, Oct 16, 2022

I’ve been experiencing this exact issue today, and took the above sandbox and added vue-i18n-bridge following the instructions, and I still see the same error message…

Here’s the updated sandbox:

https://codesandbox.io/s/mre-vue-i18n-normalize-is-not-a-function-forked-guqn1s

Read more comments on GitHub >

github_iconTop Results From Across the Web

String.prototype.normalize() - JavaScript - MDN Web Docs
A RangeError is thrown if form isn't one of the values specified above. Description. Unicode assigns a unique numerical value, called a code ......
Read more >
What's the point of String.normalize()? - Stack Overflow
normalize () is an inbuilt function in javascript which is used to return a Unicode normalisation form of a given input string. with...
Read more >
Java function normalize("NFD") is not working in Boomi
Hi Team , I have a requirement to use normalize("NFD") function in Javascript . This function is working as expected when i am...
Read more >
"normalize is not a function error" : r/internxt - Reddit
Keep getting this error whenever i try to upload something...could i any suggestions to try something different?
Read more >
JavaScript: String normalize() method - TechOnTheNet
In JavaScript, normalize() is a string method that is used to convert a string ... The normalize() method does not change the value...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found