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

umi-lib,部分依赖放在dependencies中导致打包umd时报错 #2126

Closed
NexxLuo opened this issue Mar 19, 2019 · 7 comments
Closed

umi-lib,部分依赖放在dependencies中导致打包umd时报错 #2126

NexxLuo opened this issue Mar 19, 2019 · 7 comments

Comments

@NexxLuo
Copy link
Contributor

NexxLuo commented Mar 19, 2019

使用umi-lib打包组件时,某些情况下依赖如果放在dependencies中,会导致打包umd时报错,
比如下图,如果把react放在peerDependencies中就能正常打包。

但是peerDependencies中的依赖不会被打包到输出文件中,那么下述情况就会依赖外部的react,必须在html中另行引入react的umd文件。

image

image

Context

  • Umi Version:1.2.0
  • Node Version: v10.15.3
  • Platform: Windows 10
@clock157
Copy link
Contributor

@NexxLuo
Copy link
Contributor Author

NexxLuo commented Mar 19, 2019

这是约定的规则: https://github.com/umijs/umi/tree/master/packages/umi-library#%E5%85%B3%E4%BA%8E-dependenciespeerdependencies-%E5%92%8C-external

peerDependencies是这样约定的没错,但是很多组件需要放到dependencies中进行打包,我的项目中就存在好几个第三方组件放到dependencies中打包不成功的问题

@NexxLuo
Copy link
Contributor Author

NexxLuo commented Mar 19, 2019

rollup中有解决方案https://rollupjs.org/guide/en#error-name-is-not-exported-by-module-
但是使用这种方式难免会出现配置很多namedExports,如下图:
image

这种该如何解决?
因为想将组件打包成umd包供浏览器script引入,出现这种问题导致无法实现。

@sorrycc
Copy link
Member

sorrycc commented Mar 19, 2019

可能和 #2130 有关。

@NexxLuo
Copy link
Contributor Author

NexxLuo commented Mar 20, 2019

可能和 #2130 有关。

更新了1.2.2,依然是同样的问题。

@sorrycc
Copy link
Member

sorrycc commented Mar 20, 2019

给可复现步骤。

@stale
Copy link

stale bot commented May 19, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label May 19, 2019
@stale stale bot closed this as completed May 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants