Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TypeScript] [All] 无法找到模块“element-plus/dist/locale/zh-cn.mjs”的声明文件 #13614

Closed
WangJincheng4869 opened this issue Jul 18, 2023 · 20 comments
Labels

Comments

@WangJincheng4869
Copy link

Bug Type: TypeScript

Environment

  • Vue Version: 3.2.47
  • Element Plus Version: 2.3.8
  • Browser / OS: UserAgent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36 Edg/113.0.1774.35
  • Build Tool: Vite

Reproduction

Related Component

  • All

Reproduction Link

Docs

Steps to reproduce

2.3.8版本改变了原有的国际化方式,是不是忘记添加声明文件了

无法找到模块“element-plus/dist/locale/zh-cn.mjs”的声明文件。“D:/Web Workspace/CODE_Develop/Service_Products/BasicPaper/webCode/basic-paper-cloud-vue3/node_modules/.pnpm/element-plus@2.3.8_vue@3.3.4/node_modules/element-plus/dist/locale/zh-cn.mjs”隐式拥有 "any" 类型。
  如果“element-plus”包实际公开了此模块,请尝试添加包含 `declare module‘element-plus/dist/locale/zh-cn.mjs';` 的新声明(.d.ts)文件ts(7016)

What is Expected?

内置类型,不提示此错误

What is actually happening?

存在类型错误提示

Additional comments

(empty)

@chenxch
Copy link
Member

chenxch commented Jul 18, 2023

ref to #13609

@WangJincheng4869
Copy link
Author

ref to #13609

我看这个,但不是同一个问题,引入mjs后报错。我目前是通过自己写声明文件解决的。

无法找到模块“element-plus/dist/locale/zh-cn.mjs”的声明文件。“D:/Web Workspace/CODE_Develop/Service_Products/BasicPaper/webCode/basic-paper-cloud-vue3/node_modules/.pnpm/element-plus@2.3.8_vue@3.3.4/node_modules/element-plus/dist/locale/zh-cn.mjs”隐式拥有 "any" 类型。
  如果“element-plus”包实际公开了此模块,请尝试添加包含 `declare module‘element-plus/dist/locale/zh-cn.mjs';` 的新声明(.d.ts)文件ts(7016)

@WangJincheng4869
Copy link
Author

ref to #13609

我在加了以下内容报错才消失

declare module 'element-plus/dist/locale/zh-cn.mjs' {
  const zhLocale: any;
  export default zhLocale;
}

declare module 'element-plus/dist/locale/en.mjs' {
  const enLocale: any;
  export default enLocale;
}

@chenxch
Copy link
Member

chenxch commented Jul 18, 2023

试一下在tsconfig 文件 types中添加locale声明看看

{
  "types": [..., "element-plus/lib/locale"]
}

@WangJincheng4869
Copy link
Author

"element-plus/lib/locale"

不好使...

@lettered
Copy link

这个问题的原因在于有位同志更改了导出引入方式,缺少了 lib 的import。但是es还可以取,你可以先试试
把 element-plus/lib -> element-plus/es 替换用es的导出

@JackieCheung
Copy link

import zhCn from 'element-plus/es/locale/lang/zh-cn'

@XiaoBaiClassmate
Copy link

import zhCn from 'element-plus/es/locale/lang/zh-cn'

目前使用该老哥的方案

@achangchangchang
Copy link

把element-plus版本固定到2.3.7 不要加^

@Minori-ty
Copy link

import zhCn from 'element-plus/es/locale/lang/zh-cn'

亲测可以

@772778995
Copy link

再也不用 element-plus 了,小版本更新就报错,大大小小bug一堆,我真的服了

@WangJincheng4869
Copy link
Author

再也不用 element-plus 了,小版本更新就报错,大大小小bug一堆,我真的服了

这个库版本管理上的确有问题,出现这种配置不兼容的情况最起码应该添加一个大的版本号,并在版本记录中添加升级说明。显然这个库没有做到,但也不至于不用。

@DevDengChao
Copy link

建议审查 PR 流程 🤣

@jvhuaiying
Copy link

到2024年了依然存在😂

@Minori-ty
Copy link

到2024年了依然存在😂

主要还是官网提供的例子有点问题,你可以替换成import zhCn from "element-plus/es/locale/lang/zh-cn"

@jvhuaiying
Copy link

到2024年了依然存在😂

主要还是官网提供的例子有点问题,你可以替换成import zhCn from "element-plus/es/locale/lang/zh-cn"

对的,感谢,主要还是官网有点坑,原本用js是没有这个问题的,但是因为看组件部分的示例都是用的ts,所以才硬着头皮上了ts,没想到一上来就遇到这个坑😆

@Jesseszhang
Copy link

升级vscode 到最新版本 ,插件用vue-office

@leafney
Copy link

leafney commented Mar 24, 2024

劳烦开发大大们把官网中的示例代码修正一下

@jvhuaiying
Copy link

劳烦开发大大们把官网中的示例代码修正一下

+1

@chenxch
Copy link
Member

chenxch commented Apr 2, 2024

fixed #16306

@btea btea closed this as completed Apr 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests