gpt4 book ai didi

javascript - 插件 :vite:import-analysis - Failed to parse source for import analysis because the content contains invalid JS syntax. - Vue 3

转载 作者:行者123 更新时间:2023-12-05 04:26:35 58 4
gpt4 key购买 nike

我已经将我的项目从 Vite 2.x 更新到 Vite 3.0.2,突然出现这个错误:

[plugin:vite:import-analysis] Failed to parse source for importanalysis because the content contains invalid JS syntax. If you areusing JSX, make sure to name the file with the .jsx or .tsx extension.

/Volumes/Disk/Web/wce-system/src/i18n.js:51:20

Failed to parse source for import analysis because the content contains invalid JS syntax.

i18n.js 文件没有任何问题,因为它在 Vite 2.x 上运行良好,但我将代码放在这里以备不时之需:

import { nextTick } from "vue"
import { createI18n } from "vue-i18n"
import axios from "axios"
import tr from "@/locales/tr.json"
import en from "@/locales/en.json"

export const SUPPORT_LOCALES = ["tr", "en"]

export function setupI18n(options = { locale: "tr" }) {
const i18n = createI18n(options)
setI18nLanguage(i18n, options.locale)
return i18n
}

export function setI18nLanguage(i18n, locale, url) {
if (i18n.mode === "legacy") {
i18n.global.locale = locale
} else {
i18n.global.locale.value = locale
}
axios.defaults.headers.common["Accept-Language"] = locale
document.querySelector("html").setAttribute("lang", locale)
}

export async function loadLocaleMessages(i18n, locale) {
const messages = await import(
/* webpackChunkName: "locale-[request]" */ `./locales/${locale}.json`
)

i18n.global.setLocaleMessage(locale, messages.default)
return nextTick()
}

const i18n = createI18n({
legacy: false,
locale: "tr",
fallbackLocale: "tr",
globalInjection: true,
messages: {
tr,
en,
},
})

export default i18n

最佳答案

所以我想通了。这一行:

const messages = await import(
/* webpackChunkName: "locale-[request]" */ `./locales/${locale}.json`
)

应该是:

 const messages = await import(`./locales/${locale}.json`)

我无法解释为什么会这样,但我会在下面留下有关问题的链接。

Vite dynamic imports

This可能有助于进一步调查

关于javascript - 插件 :vite:import-analysis - Failed to parse source for import analysis because the content contains invalid JS syntax. - Vue 3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73033899/

58 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com