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

组件库是export default形式导出的编译报错 #818

Open
5 tasks done
aWhver opened this issue Jan 16, 2025 · 1 comment
Open
5 tasks done

组件库是export default形式导出的编译报错 #818

aWhver opened this issue Jan 16, 2025 · 1 comment

Comments

@aWhver
Copy link

aWhver commented Jan 16, 2025

Describe the bug

1、公司有自己的组件库开发团队,但是所有组件都是export default ,没有添加export {}/
2、使用插件处理时,最终编译后是这种import {AButton as __unplugin_components_1} from "/node_modules/.vite/deps/@a-button_lib_index__js.js?v=9f7b1eed";
3、但是文件a-button_lib_index__js.js里面导出的是这种形式export {
lib_default as default
// 如果添加了export { AButton } 这里会多一个下面的导出
lib_default as AButton
};
导致编译的时候直接报错:
SyntaxError: The requested module '/node_modules/.vite/deps/a-button_lib_index__js.js?v=9f7b1eed' does not provide an export named 'AButton
请问如何解决组件没有用export {}而是用export default的形式导出可以正常按需导入

Reproduction

Reproduction

System Info

windows

Used Package Manager

yarn

Validations

  • Follow our Code of Conduct
  • Read the Contributing Guide.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • Check that this is a concrete bug. For Q&A, please open a GitHub Discussion instead.
  • The provided reproduction is a minimal reproducible of the bug.
@shenjunjian
Copy link

    (componentName) => {
      if (componentName.startsWith('you-ui'))
        return {   from: '@your-ui/button'  }
      //  return '@your-ui/button'
    },

上面的2种写法自动转换成:

 import button from "@your-ui/button"

太多人问这个问题了,建议官方写在readme上

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants