element-plus: h render method can not use ElButton component

as the title

import { ElButton } from 'element-plus';
...
render() {
  return h(ELButton,{}, 'test');
}

expect: button with test text actual: Uncaught (in promise) ReferenceError: ElButton is not defined

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 18 (11 by maintainers)

Most upvoted comments

So I can confirm that this was cause by babel-component-loader because it import element-plus/lib/el-button/index.js, see the screenshot below. And because that this file was built in cjs format. image

Because of that this is not a harmony export member A.K.A. it is not a ESModule, webpack goes to this: image then we resolve this code: h(getter, {}, []); // getter is what we got resolved by webpack.

Here’s how to solve that temporarily: Assigning it to a variable, then the getter gets called, you get the actual component. image