vue-i18n-next: SyntaxError: Named export 'createI18n' not found

Reporting a bug?

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;

Expected behavior

  1. pnpm install
  2. pnpm build
  3. cd apps/docs
  4. pnpm build

Reproduction

branch: feat/date

https://github.com/huntersofbook/huntersofbook/tree/feat/date

System Info

System:
    OS: Linux 5.15 Ubuntu 22.04.1 LTS 22.04.1 LTS (Jammy Jellyfish)
    CPU: (12) x64 11th Gen Intel(R) Core(TM) i5-11400 @ 2.60GHz
    Memory: 17.10 GB / 31.12 GB
    Container: Yes
    Shell: 5.1.16 - /bin/bash
  Binaries:
    Node: 16.17.0 - /usr/bin/node
    Yarn: 1.22.19 - /usr/bin/yarn
    npm: 8.15.0 - /usr/bin/npm
  Browsers:
    Chrome: 104.0.5112.101
  npmPackages:
    vitepress: 1.0.0-alpha.10 => 1.0.0-alpha.10

Screenshot

No response

Additional context

No response

Validations

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 1
  • Comments: 18 (16 by maintainers)

Most upvoted comments

@productdevbook Thank you as always!

As found out, this issue occurs in builds when SSR is enabled. The __VUE_PROD_DEVTOOLS__ flag is expected to be set to globalThis for vue-i18n.

I have tried to enable __VUE_PROD_DEVTOOLS__ in the configure hook of the vite plugin, but for some reason it is not enabled when SSR. (And I noticed that other flags provided by vue-i18n are not enabled either)

I will continue to fix it. Please wait 🙏

I’ve just released out vue-i18n 9.3.0-beta.3 Please check it!

@productdevbook Thank you for your feedback! I’ve just fixed it and send PR, please wait 🙏 https://github.com/intlify/vue-i18n-next/pull/1152

@productdevbook Hello! I’ve just released @intlify/vite-plugin-vue-i18n v7.0.0-beta.2 Please check it!

I’ve checked your awesome hundersofbook! So, I’ve faced the error in it the below:

vitepress v1.0.0-alpha.10
✓ building client + server bundles...
⠋ rendering pages...TypeError: format2 is not a function
    at localizedFormat (file:///path/to/tmp/huntersofbook/apps/docs/docs/.vitepress/.temp/app.js:99:10)
    at watch.immediate (file:///path/to/tmp/huntersofbook/apps/docs/docs/.vitepress/.temp/app.js:2350:430)
    at callWithErrorHandling (/path/to/tmp/huntersofbook/node_modules/.pnpm/@vue+runtime-core@3.2.37/node_modules/@vue/runtime-core/dist/runtime-core.cjs.prod.js:119:22)
    at callWithAsyncErrorHandling (/path/to/tmp/huntersofbook/node_modules/.pnpm/@vue+runtime-core@3.2.37/node_modules/@vue/runtime-core/dist/runtime-core.cjs.prod.js:128:21)
    at doWatch (/path/to/tmp/huntersofbook/node_modules/.pnpm/@vue+runtime-core@3.2.37/node_modules/@vue/runtime-core/dist/runtime-core.cjs.prod.js:1280:13)
    at watch (/path/to/tmp/huntersofbook/node_modules/.pnpm/@vue+runtime-core@3.2.37/node_modules/@vue/runtime-core/dist/runtime-core.cjs.prod.js:1209:12)
    at setup (file:///path/to/tmp/huntersofbook/apps/docs/docs/.vitepress/.temp/app.js:2341:5)
    at callWithErrorHandling (/path/to/tmp/huntersofbook/node_modules/.pnpm/@vue+runtime-core@3.2.37/node_modules/@vue/runtime-core/dist/runtime-core.cjs.prod.js:119:22)
    at setupStatefulComponent (/path/to/tmp/huntersofbook/node_modules/.pnpm/@vue+runtime-core@3.2.37/node_modules/@vue/runtime-core/dist/runtime-core.cjs.prod.js:5789:29)
    at setupComponent (/path/to/tmp/huntersofbook/node_modules/.pnpm/@vue+runtime-core@3.2.37/node_modules/@vue/runtime-core/dist/runtime-core.cjs.prod.js:5770:11)
✓ rendering pages...
build complete in 11.57s.

I seem that date-fns is not to fully support cjs/mjs vite3 SSR (vitepress) requires esm, so you might want to check if your module is supported as a dual module.

Thank you for your reproduction!

Hmm 🤔 , I could not your reproduction same situation. vitepress v1 alpha is using vite@v3, so vite@v3 require native ES modules

vue-i18n v9 is not yet a full native ES modules. So we need to support it.