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.

Vitest: Error: Missing "./messages" export in "@intlify/vite-plugin-vue-i18n" package

See original GitHub issue

Reporting a bug?

I use @intlify/vite-plugin-vue-i18n to load my translation files.

When I run Vitest, im getting the following error:

Error: Missing “./messages” export in “@intlify/vite-plugin-vue-i18n” package

When I run vite or vite build, everything works as expected.

Expected behavior

The tests are using my translations.

Reproduction

vite.config.ts

import vueI18n from '@intlify/vite-plugin-vue-i18n'
import vue from '@vitejs/plugin-vue'
import { dirname, resolve } from 'node:path'
import { fileURLToPath } from 'url'
import { defineConfig } from 'vitest/config'
import GithubActionsReporter from 'vitest-github-actions-reporter'

export default defineConfig({
  plugins: [
    vue(),
    vueI18n({
      include: resolve(dirname(fileURLToPath(import.meta.url)), './src/locales/**'),
    }),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url)),
    },
  },
  test: {
    globals: true,
    environment: 'jsdom',
    include: ['**/*.unit.ts'],
    setupFiles: ['./tests/unit/setup.ts'],
    reporters: process.env.GITHUB_ACTIONS !== undefined ? new GithubActionsReporter() : 'default',
    coverage: {
      reporter: 'lcov',
    },
  },
})

tests/unit/setup.ts

import '@testing-library/jest-dom'

import { config } from '@vue/test-utils'

import { i18n } from '@/i18n'

beforeAll(() => {
  // some mocks
  vi.mock('chart.js', () => ({
    registerables: [],
    Chart: {
      register: () => null,
    },
  }))

  config.global.plugins = [ i18n ]
})

@/i18n.ts

import messages from '@intlify/vite-plugin-vue-i18n/messages'
import { createI18n } from 'vue-i18n'

export const i18n = createI18n({
  locale: 'nl',
  fallbackLocale: 'en',
  legacy: false,
  messages,
})

Issue Package

vite-plugin-vue-i18n

System Info

System:
    OS: macOS 12.4
    CPU: (8) arm64 Apple M1 Pro
    Memory: 82.83 MB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.15.1 - /opt/homebrew/opt/node@16/bin/node
    Yarn: 1.22.19 - /opt/homebrew/bin/yarn
    npm: 8.11.0 - /opt/homebrew/opt/node@16/bin/npm
  Browsers:
    Firefox: 102.0.1
    Safari: 15.5
  npmPackages:
    @intlify/vite-plugin-vue-i18n: ^5.0.0 => 5.0.0
    vite: ^3.0.0 => 3.0.0
    vue: ^3.2.0 => 3.2.37
    vue-i18n: 9 => 9.1.10

Screenshot

image

Additional context

No response

Validations

  • Read the Contributing Guidelines.
  • Read the README
  • Check that there isn’t already an issue that reports the same bug to avoid creating a duplicate.
  • Check that this is a concrete bug. For Q&A open a GitHub Discussion.

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:6
  • Comments:13 (7 by maintainers)

github_iconTop GitHub Comments

4reactions
kazuponcommented, Jul 20, 2022

Thanks! I could see this issue

3reactions
kazuponcommented, Jul 25, 2022

That seems to be a bug of Vite SSR ref: github discussions on https://github.com/vitejs/vite/discussions/9356

ref: github issues on vite https://github.com/vitejs/vite/issues/9364

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to import messages as JSON files (Vite/Typescript) #63
The error message is "Cannot find module '@intlify/vite-plugin-vue-i18n/messages' or its corresponding type declarations.ts(2307)". When I try ...
Read more >
@intlify/vite-plugin-vue-i18n - npm
Start using @intlify/vite-plugin-vue-i18n in your project by running ... TypeScript icon, indicating that this package has built-in type ...
Read more >
Internationalization for vue 3 vite with i18n - Stack Overflow
The problem I am facing here, is that i currently have to import and setup the t variable for every component to use...
Read more >
vite does not provide an export named 'default - You.com
This is a github project that I found when I searched for error messages when I ... module '@intlify/vite-plugin-vue-i18n' does not provide an...
Read more >
Optimization - Vue I18n - Intlify
message compiler + runtime: vue-i18n.esm-bundler.js ... from 'url' import vueI18n from '@intlify/vite-plugin-vue-i18n' export default ...
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