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.

SyntaxError: Named export 'createI18n' not found

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:18 (9 by maintainers)

github_iconTop GitHub Comments

3reactions
kazuponcommented, Aug 31, 2022

@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 🙏

2reactions
kazuponcommented, Sep 2, 2022

@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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

CommonJS modules can always be imported via the default ...
SyntaxError : Named export 'createI18n' not found. The requested module 'vue-i18n/dist/vue-i18n.runtime.esm-bundler.js' is a CommonJS module, ...
Read more >
Vue-i18n do not have default export - Stack Overflow
And backtrack the key word VueI18n in the import, I found it doesn't have any default export. typescript · vue.js · vue-i18n ·...
Read more >
Common Issues - Nuxt Vite
Uncaught SyntaxError: The requested module ... does not provide an export named 'default'. Vite has an issue for pre-bundling dependencies ...
Read more >
Breaking Changes - Vue I18n
Vue I18n is no longer a class but a set of functions. Instead of writing new VueI18n() , you now have to call...
Read more >
@intlify/vite-plugin-vue-i18n - npm
Vite plugin for Vue I18n. Latest version: 7.0.0, last published: 15 days ago. Start using @intlify/vite-plugin-vue-i18n in your project by ...
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