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.

why vue-i18n cannot build with vite-ssg

See original GitHub issue

I’m running the vite-ssg build, but the console always show these informations:

[vite-ssg] An internal error occurred. [vite-ssg] Please report an issue, if none already exists: https://github.com/antfu/vite-ssg/issues (node:17492) UnhandledPromiseRejectionWarning: file:///E:/01_Workstation/03_Codes/Vue3/whatever-fronted/.vite-ssg-temp/main.mjs:3 import { createI18n, useI18n } from ‘vue-i18n/dist/vue-i18n.runtime.esm-bundler.js’; ^^^^^^^ SyntaxError: Named export ‘useI18n’ 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 (internal/modules/esm/module_job.js:124:21)
at async ModuleJob.run (internal/modules/esm/module_job.js:179:5)
at async Loader.import (internal/modules/esm/loader.js:178:24)
at async build (file:///E:/01_Workstation/03_Codes/Vue3/whatever-fronted/node_modules/.pnpm/vite-ssg@0.20.2_gv3f3qqio2remjcjfesyn4w42y/node_modules/vite-ssg/dist/chunks/build.mjs:171:87)    
at async Object.handler (file:///E:/01_Workstation/03_Codes/Vue3/whatever-fronted/node_modules/.pnpm/vite-ssg@0.20.2_gv3f3qqio2remjcjfesyn4w42y/node_modules/vite-ssg/dist/node/cli.mjs:20:3) 

(Use node --trace-warnings ... to show where the warning was created) (node:17492) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2) (node:17492) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

I don’t why cause this problem

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:6

github_iconTop GitHub Comments

4reactions
ovrayscommented, Oct 20, 2022

Update your ssr configuration in vite.config.ts:

export default defineConfig({
  plugins: [vue, vueI18n({
    include: resolve(dirname(fileURLToPath(import.meta.url)), './locales/**'),
  })],
  ssr: {
    // SSG Vue-i18n workaround
    noExternal: [/vue-i18n/],
  }
})

I think this should work for other packages too.

0reactions
yankeeinlondoncommented, Oct 6, 2022

I mean you can set "type": "module" in your package.json file but this might brake something else. Super annoying this back and force with CommonJS and ES

I ran into this problem and get the error regardless of whether my type is set to “module” or “commonjs”.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Nuxt 3 integration - Vue I18n - Intlify
We will introduce Vue I18n integration for Nuxt 3. The following is a tutorial on setting up a Nuxt 3 application from the...
Read more >
Is there a way to configure Storybook to use the same Vite ...
My goal is that my Storybook config and stack are the same as the app, so Storybook will accurately reflect implemented components. Maintaining ......
Read more >
Use This Vite Vue.js 3 Starter Template Instead - YouTube
techVitesse is a Vue.js 3 starter template made with Vite and a lot ... 17:43 Testing out SSG 18:21 Dynamic Routes 🗂️ 🗂️...
Read more >
Vitesse: Opinionated Vite Starter Template - Morioh
vite-plugin-vue-i18n - Vite plugin for Vue I18n ... vitecamp by @nekobc1998923 - Like Vitesse but without SSG/SSR/File based routing, includes Element Plus ...
Read more >
[vue warn]: component provided template option but runtime ...
Currently the instructions to make vue-router@next with vue@next do not take into consideration the scenario where the vue application was generated by vite...
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