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] [message, message-box] when tsconfig.json set moduleResolution to nodenext or bundler, ElMessage can not be imported. #11818

Closed
wangxdmm opened this issue Mar 4, 2023 · 19 comments · Fixed by #13443
Labels
Project::Bug Something isn't working Quality::TypeScript Related this issue is related to type definition

Comments

@wangxdmm
Copy link

wangxdmm commented Mar 4, 2023

Bug Type: TypeScript

Environment

  • Vue Version: 3.2.47
  • Element Plus Version: 2.2.33
  • Browser / OS: 110.0.5481.100(正式版本) (x86_64)/mac os 12.6.3
  • Build Tool: Other

Reproduction

Related Component

  • el-message
  • el-message-box

Reproduction Link

Github Repo

Steps to reproduce

# 1.
pnpm install

# I set tsconfig.json (moduleResolution to nodenext)
# open index.ts we can see:

# Module '"element-plus"' has no exported member 'ElMessage'. Did you mean to use 'import ElMessage from "element-plus"' instead?ts


# 2. replace by new exports content
pnpm replace

# the error will remove

# 3.

pnpm restore

# the error will show again

What is Expected?

no error

What is actually happening?

has error

Additional comments

(empty)

@ModyQyW
Copy link
Contributor

ModyQyW commented Apr 25, 2023

el-notification is also related.

@aknot242
Copy link

el-button and el-dialog also appear to be experiencing this error.

@FabianMontoya
Copy link

FabianMontoya commented May 5, 2023

It should be related with a break change into the TS versionof @vue/tsconfig, I was able to run my project without error with the following versions:

"dependencies": {
    "element-plus": "^2.3.4",
    "vue": "^3.2.47"
}
"devDependencies": {
    "@vitejs/plugin-vue": "^4.2.1",
    "@vue/tsconfig": "0.1.3",  /* <-- important fix */
    "typescript": "4.9.5",  /* <-- important fix */
    "vite": "^4.3.5",
    "vue-tsc": "^1.6.4"
}

@FabianMontoya
Copy link

The problem is with typescript > 4.9.4
for that reason we can not update @vue/tsconfig to an upper version than 0.1.3 and obviously typescript neither.

@ModyQyW
Copy link
Contributor

ModyQyW commented May 6, 2023

The problem is with typescript > 4.9.4 for that reason we can not update @vue/tsconfig to an upper version than 0.1.3 and obviously typescript neither.

@FabianMontoya You can.

This problem is caused by compilerOptions.moduleResolution: "bundler" and element-plus exports field in package.json.

If you want to use typescript@5 and @vue/tsconfig@0.3 you have to set compilerOptions.moduleResolution: "node" in tsconfig.json to override @vue/tsconfig@0.3 config.

If not work for you, please see #11818 (comment).

@aknot242
Copy link

aknot242 commented May 6, 2023

The problem is with typescript > 4.9.4 for that reason we can not update @vue/tsconfig to an upper version than 0.1.3 and obviously typescript neither.

@FabianMontoya You can.

This problem is caused by compilerOptions.moduleResolution: "bundler" and element-plus exports field in package.json.

If you want to use typescript@5 and @vue/tsconfig@0.3 you have to set compilerOptions.moduleResolution: "node" in tsconfig.json to override @vue/tsconfig@0.3 config.

Thank you for posting this, @ModyQyW . This solution worked for me on TypeScript 5.0.4.

@toplinuxsir
Copy link

toplinuxsir commented May 9, 2023

@aknot242 @ModyQyW
I have use typescript@5 and @vue/tsconfig@0.3
tsconfig.json

{
   "compilerOptions.moduleResolution": "node",

  "files": [],
  "references": [
    {
      "path": "./tsconfig.node.json"
    },
    {
      "path": "./tsconfig.app.json"
    },
    {
      "path": "./tsconfig.vitest.json"
    }
  ]
}

npm run build error ,not working

src/App.vue:4:10 - error TS2614: Module '"element-plus"' has no exported member 'ElMenu'. Did you mean to use 'import ElMenu from "element-plus"'

How to resolve ? Thanks!

@xiefangqing
Copy link

依赖:

 "dependencies": {
    "@element-plus/icons-vue": "^2.1.0",
    "element-plus": "^2.3.4",
    "vue": "^3.2.47",
    "vue-router": "^4.1.6"
  },
  "devDependencies": {
    "@types/node": "^18.16.3",
    "@vitejs/plugin-vue": "^4.1.0",
    "sass": "^1.62.1",
    "typescript": "^5.0.2",
    "vite": "^4.3.2",
    "vue-tsc": "^1.4.2"
  }

import { ElMessage } from 'element-plus';

报错:
error TS2614: Module '"element-plus"' has no exported member 'ElMessage'. Did you mean to use 'import ElMessage from "element-plus"' instead?

@aknot242
Copy link

aknot242 commented May 9, 2023

@aknot242 @ModyQyW I have use typescript@5 and @vue/tsconfig@0.3 tsconfig.json

{
   "compilerOptions.moduleResolution": "node",

  "files": [],
  "references": [
    {
      "path": "./tsconfig.node.json"
    },
    {
      "path": "./tsconfig.app.json"
    },
    {
      "path": "./tsconfig.vitest.json"
    }
  ]
}

npm run build error ,not working

src/App.vue:4:10 - error TS2614: Module '"element-plus"' has no exported member 'ElMenu'. Did you mean to use 'import ElMenu from "element-plus"'

How to resolve ? Thanks!

@toplinuxsir try putting the following in each of your tsconfig files (tsconfig.node.json, tsconfig.app.json, tsconfig.vitest.json)

{
  "compilerOptions": {
    "moduleResolution": "node"
  }
}

@toplinuxsir
Copy link

@aknot242 Thanks! It works!

@Sheepeer
Copy link

@aknot242 Sry the way not work for me, or could U pls help to see is there any error with my configration?
image
image

@ModyQyW
Copy link
Contributor

ModyQyW commented May 17, 2023

@aknot242 @ModyQyW I have use typescript@5 and @vue/tsconfig@0.3 tsconfig.json

{
   "compilerOptions.moduleResolution": "node",

  "files": [],
  "references": [
    {
      "path": "./tsconfig.node.json"
    },
    {
      "path": "./tsconfig.app.json"
    },
    {
      "path": "./tsconfig.vitest.json"
    }
  ]
}

npm run build error ,not working

src/App.vue:4:10 - error TS2614: Module '"element-plus"' has no exported member 'ElMenu'. Did you mean to use 'import ElMenu from "element-plus"'

How to resolve ? Thanks!

@toplinuxsir try putting the following in each of your tsconfig files (tsconfig.node.json, tsconfig.app.json, tsconfig.vitest.json)

{
  "compilerOptions": {
    "moduleResolution": "node"
  }
}

@Sheepeer Is it not worked for you?

@Sheepeer
Copy link

Yes, I put it in all my three tsconfig files and there is no changement:
image
image
image
image
image

@ModyQyW
Copy link
Contributor

ModyQyW commented May 17, 2023

Yes, I put it in all my three tsconfig files and there is no changement:

@Sheepeer Have you reloaded vscode window or restarted vscode?

@Sheepeer
Copy link

Yes, I put it in all my three tsconfig files and there is no changement:

@Sheepeer Have you reloaded vscode window or restarted vscode?

OHHH I forgot! So much Thx!!!

@Dreamacro
Copy link

Any progress?

Once "moduleResolution": "node" is used, import ElementPlus from 'unplugin-element-plus/vite' in vite.config.ts will report another import error.

@slimvan
Copy link

slimvan commented Jun 25, 2023

Yes, I put it in all my three tsconfig files and there is no changement: image image image image image

Node

@zhuying547
Copy link
Contributor

zhuying547 commented Jul 1, 2023

#12602 Good Job

zhuying547 added a commit to zhuying547/element-plus that referenced this issue Jul 1, 2023
@zhuying547 zhuying547 mentioned this issue Jul 1, 2023
3 tasks
@adminChina
Copy link

good, Simply modify tsconfig.app.json

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Project::Bug Something isn't working Quality::TypeScript Related this issue is related to type definition
Projects
None yet