R
R
resibe2021-11-15 01:40:34
Internationalization and localization
resibe, 2021-11-15 01:40:34

How to install vue-i18n + typescript?

Hello, I have created an empty vue 3 project with TypeScript and run it and vue add i18n
then I get

This dependency was not found:
* vue-i18n in ./src/i18n.ts
To install it, you can run: npm install --save vue-i18n

After executing yarn add vue-i18n
I get
This dependency was not found:

* vue-i18n in ./src/i18n.ts

To install it, you can run: npm install --save vue-i18n
ERROR in src/i18n.ts:1:10
TS2614: Module '"../node_modules/vue-i18n/types"' has no exported member 'createI18n'. Did you mean to use 'import createI18n from "../node_modules/vue-i18n/types"' instead?
  > 1 | import { createI18n, LocaleMessages, VueMessageType } from "vue-i18n";
      |          ^^^^^^^^^^
    2 |
    3 | /**
    4 |  * Load locale messages

ERROR in src/i18n.ts:1:38
TS2614: Module '"../node_modules/vue-i18n/types"' has no exported member 'VueMessageType'. Did you mean to use 'import VueMessageType from "../node_modules/vue-i18n/types"' instead?
  > 1 | import { createI18n, LocaleMessages, VueMessageType } from "vue-i18n";
      |                                      ^^^^^^^^^^^^^^
    2 |
    3 | /**
    4 |  * Load locale messages

ERROR in src/i18n.ts:9:32
TS2315: Type 'LocaleMessages' is not generic.
     7 |  * See: https://github.com/intlify/vue-i18n-loader#rocket-i18n-resource-pre-compilation
     8 |  */
  >  9 | function loadLocaleMessages(): LocaleMessages<VueMessageType> {
       |                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    10 |   const locales = require.context(
    11 |     "./locales",
    12 |     true,

ERROR in src/i18n.ts:15:19
TS2315: Type 'LocaleMessages' is not generic.
    13 |     /[A-Za-z0-9-_,\s]+\.json$/i
    14 |   );
  > 15 |   const messages: LocaleMessages<VueMessageType> = {};
       |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    16 |   locales.keys().forEach((key) => {
    17 |     const matched = key.match(/([A-Za-z0-9-_]+)\./i);
    18 |     if (matched && matched.length > 1) {

What I did wrong, everything works without TS
It's strange that the vscode module itself sees
619192b15efbb900151480.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Aetae, 2021-11-15
@resibe

https://vue-i18n.intlify.dev/installation.html#es-...
yarn add [email protected]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question