Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
4 tasks done
yooouuri opened this issue Jul 15, 2022 · 13 comments
Closed
4 tasks done

Comments

@yooouuri
Copy link

yooouuri commented Jul 15, 2022

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.
@yooouuri yooouuri added the Status: Review Needed Request for review comments label Jul 15, 2022
@kazupon kazupon added Package: vite-plugin-vue-i18n and removed Status: Review Needed Request for review comments labels Jul 16, 2022
@kazupon
Copy link
Member

kazupon commented Jul 16, 2022

Thank you for your reporting!

Unfortunately, I could not reproduce this issue 😞
so, I seem that your reproduction codes include the domain-specific codes (e.g. GithubActionsReporter).
Could you give us minimum reproduction codes, please? 🙏

@kazupon kazupon added the Status: Need More Info Lacks enough info to make progress label Jul 16, 2022
@mHooshdar
Copy link

I have the same issue with vitest after upgrading the vitest to version v0.17.0.
https://github.com/vitest-dev/vitest/releases/tag/v0.17.0

It can be reproduced by using the latest version of @intlify/vite-plugin-vue-i18n and latest version of vitest

@alfeg
Copy link

alfeg commented Jul 19, 2022

Same for me after updating vite to v3 and @intlify/vite-plugin-vue-i18n to latest, but with additional output

Error: Missing "./messages" export in "@intlify/vite-plugin-vue-i18n" package
 ❯ bail ../../../../../../../../../C:/src/xxxxx/src/xxxxxxxxxxx.WebApp/node_modules/vite/dist/node/chunks/dep-1513d487.js:33603:8
 ❯ resolve ../../../../../../../../../C:/src/xxxxx/src/xxxxxxxxxxx.WebApp/node_modules/vite/dist/node/chunks/dep-1513d487.js:33680:10
 ❯ resolveExports ../../../../../../../../../C:/src/xxxxx/src/xxxxxxxxxxx.WebApp/node_modules/vite/dist/node/chunks/dep-1513d487.js:34417:12
 ❯ resolveDeepImport ../../../../../../../../../C:/src/xxxxx/src/xxxxxxxxxxx.WebApp/node_modules/vite/dist/node/chunks/dep-1513d487.js:34435:31
 ❯ tryNodeResolve ../../../../../../../../../C:/src/xxxxx/src/xxxxxxxxxxx.WebApp/node_modules/vite/dist/node/chunks/dep-1513d487.js:34160:20
 ❯ isValidPackageEntry ../../../../../../../../../C:/src/xxxxx/src/xxxxxxxxxxx.WebApp/node_modules/vite/dist/node/chunks/dep-1513d487.js:38020:18
 ❯ ../../../../../../../../../C:/src/xxxxx/src/xxxxxxxxxxx.WebApp/node_modules/vite/dist/node/chunks/dep-1513d487.js:38030:65
 ❯ shouldExternalizeForSSR ../../../../../../../../../C:/src/xxxxx/src/xxxxxxxxxxx.WebApp/node_modules/vite/dist/node/chunks/dep-1513d487.js:37976:12
 ❯ TransformContext.transform ../../../../../../../../../C:/src/xxxxx/src/xxxxxxxxxxx.WebApp/node_modules/vite/dist/node/chunks/dep-1513d487.js:40258:34

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/21]⎯

Test Files  21 failed (21)
     Tests  no tests
      Time  3.93s (in thread 0ms, Infinity%)

FATAL ERROR: v8::FromJust Maybe value is Nothing.
 1: 00007FF6F2767C4F v8::internal::CodeObjectRegistry::~CodeObjectRegistry+114207
 2: 00007FF6F26F5EC6 DSA_meth_get_flags+65542
 3: 00007FF6F26F6D7D node::OnFatalError+301
 4: 00007FF6F30160D5 v8::V8::FromJustIsNothing+53
 5: 00007FF6F26DEEB3 v8::base::CPU::has_sse+31507
 6: 00007FF6F27CABC7 uv_timer_stop+1207
 7: 00007FF6F27C715B uv_async_send+331
 8: 00007FF6F27C68EC uv_loop_init+1292
 9: 00007FF6F27C6A8A uv_run+202
10: 00007FF6F27958F5 node::SpinEventLoop+309
11: 00007FF6F262E520 v8::internal::interpreter::BytecodeLabel::bind+35712
12: 00007FF6F2629B78 v8::internal::interpreter::BytecodeLabel::bind+16856
13: 00007FF6F27B715D uv_poll_stop+557
14: 00007FF6F35D0740 v8::internal::compiler::RepresentationChanger::Uint32OverflowOperatorFor+146416
15: 00007FF87F3F54E0 BaseThreadInitThunk+16
16: 00007FF880CC485B RtlUserThreadStart+43

System Info

  System:
    OS: Windows 10 10.0.22000
    CPU: (16) x64 AMD Ryzen 7 3800X 8-Core Processor
    Memory: 10.30 GB / 31.91 GB
  Binaries:
    Node: 16.16.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.4 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
    npm: 8.13.2 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Chrome: 103.0.5060.114
    Edge: Spartan (44.22000.120.0), Chromium (103.0.1264.49)
    Internet Explorer: 11.0.22000.120
  npmPackages:
    @intlify/vite-plugin-vue-i18n: ^5.0.0 => 5.0.0
    vite: ^3.0.2 => 3.0.2
    vitest: ^0.18.1 => 0.18.1 
    vue: ^3.2.37 => 3.2.37
    vue-i18n: ^9.1.10 => 9.1.10

@marekvospel
Copy link
Contributor

Got the same issue with the following dependencies
image

I've created a minimum reproduction repository @kazupon
https://github.com/marekvospel/vitest-vite-plugin-vue-i18n

I used pnpm, but the issue also happens with npm & yarn

@kazupon
Copy link
Member

kazupon commented Jul 20, 2022

Thanks!
I could see this issue

@kazupon kazupon added Type: Bug Bug or Bug fixes and removed Status: Need More Info Lacks enough info to make progress labels Jul 20, 2022
@mHooshdar
Copy link

These changes and the latest release do not fix the problem

I have a problem with building the project too. it said:

import { createI18n, useI18n } from "vue-i18n/dist/vue-i18n.runtime.esm-bundler.js";
         ^^^^^^^^^^
SyntaxError: Named export 'createI18n' not found. The requested module 'vue-i18n/dist/vue-i18n.runtime.esm-bundler.js' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'vue-i18n/dist/vue-i18n.runtime.esm-bundler.js';
const { createI18n, useI18n } = pkg;

    at ModuleJob._instantiate (node:internal/modules/esm/module_job:128:21)
    at async ModuleJob.run (node:internal/modules/esm/module_job:194:5)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:409:24)
    at async build (file:///Users/mhooshdar/Desktop/Projects/vuilerplate/node_modules/.pnpm/vite-ssg@0.20.2_bc535nzjtcqlryzrekyvursaoq/node_modules/vite-ssg/dist/chunks/build.mjs:171:87)
    at async Object.handler (file:///Users/mhooshdar/Desktop/Projects/vuilerplate/node_modules/.pnpm/vite-ssg@0.20.2_bc535nzjtcqlryzrekyvursaoq/node_modules/vite-ssg/dist/node/cli.mjs:20:3)

@alfeg
Copy link

alfeg commented Jul 25, 2022

Not sure what I'm doing wrong
But the fix don't help

FATAL ERROR: v8::ToLocalChecked Empty MaybeLocal.
 1: 00007FF7479F7C4F v8::internal::CodeObjectRegistry::~CodeObjectRegistry+114207
 2: 00007FF747985EC6 DSA_meth_get_flags+65542
 3: 00007FF747986D7D node::OnFatalError+301
 4: 00007FF7482C41E5 v8::V8::ToLocalEmpty+53
 5: 00007FF74797DF66 DSA_meth_get_flags+32934
 6: 00007FF7479718CB v8::base::CPU::has_sse+42283
 7: 00007FF747A5ABC7 uv_timer_stop+1207
 8: 00007FF747A5715B uv_async_send+331
 9: 00007FF747A568EC uv_loop_init+1292
10: 00007FF747A56A8A uv_run+202
11: 00007FF747A258F5 node::SpinEventLoop+309
12: 00007FF7478BE520 v8::internal::interpreter::BytecodeLabel::bind+35712
13: 00007FF7478B9B78 v8::internal::interpreter::BytecodeLabel::bind+16856
14: 00007FF747A4715D uv_poll_stop+557
15: 00007FF748860740 v8::internal::compiler::RepresentationChanger::Uint32OverflowOperatorFor+146416
16: 00007FF87F3F54E0 BaseThreadInitThunk+16
17: 00007FF880CC485B RtlUserThreadStart+43

Provided repro from @marekvospel is failing too after packages update to the latest: https://github.com/marekvospel/vitest-vite-plugin-vue-i18n

@yooouuri
Copy link
Author

yooouuri commented Jul 25, 2022

Updated @intlify/vite-plugin-vue-i18n in https://github.com/yooouuri/vitest-vite-plugin-vue-i18n

@kazupon the error is still present

@kazupon
Copy link
Member

kazupon commented Jul 25, 2022

Yeah, Unfortunately, I could not still resolve this issue 😞
@intlify/vite-plugin-vue-i18n/messages is virtual module of @intlify/vite-plugin-vue-i18 plugin

I recognize that the virtual module is automatically externalized in SSR.
However, it seems that vite is not done.

@kazupon
Copy link
Member

kazupon commented Jul 25, 2022

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

ref: github issues on vite
vitejs/vite#9364

@marekvospel
Copy link
Contributor

marekvospel commented Jul 29, 2022

@kazupon vitejs/vite#9405 was merged. After updating vite to ^3.0.4 this issue no longer happens. (I've updated my repro repo https://github.com/marekvospel/vitest-vite-plugin-vue-i18n)
This issue should probably be closed

@kazupon
Copy link
Member

kazupon commented Jul 29, 2022

Thank you for your taking the time to let us know!
Okay, I'll close this issue.

@kazupon kazupon closed this as completed Jul 29, 2022
@kazupon kazupon removed the Status: Need More Info Lacks enough info to make progress label Jul 29, 2022
@chemeng
Copy link

chemeng commented Aug 3, 2022

These changes and the latest release do not fix the problem

I have a problem with building the project too. it said:

import { createI18n, useI18n } from "vue-i18n/dist/vue-i18n.runtime.esm-bundler.js";
         ^^^^^^^^^^
SyntaxError: Named export 'createI18n' not found. The requested module 'vue-i18n/dist/vue-i18n.runtime.esm-bundler.js' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'vue-i18n/dist/vue-i18n.runtime.esm-bundler.js';
const { createI18n, useI18n } = pkg;

    at ModuleJob._instantiate (node:internal/modules/esm/module_job:128:21)
    at async ModuleJob.run (node:internal/modules/esm/module_job:194:5)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:409:24)
    at async build (file:///Users/mhooshdar/Desktop/Projects/vuilerplate/node_modules/.pnpm/vite-ssg@0.20.2_bc535nzjtcqlryzrekyvursaoq/node_modules/vite-ssg/dist/chunks/build.mjs:171:87)
    at async Object.handler (file:///Users/mhooshdar/Desktop/Projects/vuilerplate/node_modules/.pnpm/vite-ssg@0.20.2_bc535nzjtcqlryzrekyvursaoq/node_modules/vite-ssg/dist/node/cli.mjs:20:3)

@mHooshdar did figure this out? I was only able to get this working by specifying runtimeOnly: false which kind of defeats the purpose of this option I guess.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants