Skip to content
This repository has been archived by the owner on Aug 30, 2024. It is now read-only.

生产版本下element-plus的locale无法使用 #16

Closed
lilkui opened this issue Apr 21, 2021 · 3 comments
Closed

生产版本下element-plus的locale无法使用 #16

lilkui opened this issue Apr 21, 2021 · 3 comments
Labels
bug Something isn't working

Comments

@lilkui
Copy link

lilkui commented Apr 21, 2021

main.js

import { createApp } from 'vue'
import { locale } from 'element-plus'
import lang from 'element-plus/lib/locale/lang/zh-cn'

locale(lang)
createApp(App)

vite.config.js

export default {
  plugins: [
    styleImport({
      libs: [
        {
          libraryName: "element-plus",
          esModule: true,
          ensureStyleFile: true,
          resolveStyle: (name) => {
            return `element-plus/lib/theme-chalk/${name}.css`;
          },
          resolveComponent: (name) => {
            return `element-plus/lib/${name}`;
          },
        },
      ],
    }),
  ],
};

经过vite build过后,预览生产版本时发现报错Uncaught TypeError: v is not a function,报错的位置在locale(lang)

是不是配置有误?求帮助,谢谢

@anncwb anncwb added the bug Something isn't working label Apr 23, 2021
@anncwb
Copy link
Collaborator

anncwb commented Apr 23, 2021

生产模式下打开这两个就可以

{
ensureStyleFile: true,
 esModule: true,
}

@catch6
Copy link

catch6 commented Jun 18, 2021

生产模式下打开这两个就可以

{
ensureStyleFile: true,
 esModule: true,
}

按照这个做,没有效果,仍然会提示 Uncaught TypeError: y is not a function

@andylizi
Copy link

临时 workaround:

if (typeof locale === "function") {
    locale(lang);       // dev
} else {
    // @ts-ignore
    locale.use(lang);   // production
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants