nonzzz / vite-plugin-compression

vite plugin. compress your bundle file.
MIT License
162 stars 9 forks source link

使用 `import compression from 'vite-plugin-compression'` 时运行报错 `TypeError: compression is not a function` #13

Closed ModyQyW closed 1 year ago

ModyQyW commented 1 year ago

Bug report 🐞

https://github.com/ModyQyW/playground

Version & Environment

$ node -v
v18.13.0
$ yarn -v
1.22.19

我已阅读过文档,文档内的建议用法是 import { compression } from 'vite-plugin-compression'

但我倾向于使用默认导入,而且代码内也有默认导出,没有提示类型错误,不太明白为什么不能使用 import compression from 'vite-plugin-compression'

Expection

正常运行

Actual results (or Errors)

image
nonzzz commented 1 year ago

@ModyQyW 感谢你的反馈。 我查看了你的repo ( 我发现你设置了type=module 按照vite 自己的逻辑 他会认为他是一个纯esm 这时候原有的导出功能已经不够用了。 我会发布一个新版本解决这个问题。

ModyQyW commented 1 year ago

应该在 package.json 里面补 exports 就好了,我可以提一个 pr

nonzzz commented 1 year ago

@ModyQyW 嗯。 因为 type=module 这种方式 node 需要重新导入模块。欢迎PR

nonzzz commented 1 year ago

@ModyQyW 0.6.1 版本已经发布 可以尝试一下。

ModyQyW commented 1 year ago

还是不太正常,把我整不会了。

image
nonzzz commented 1 year ago

这是一个构建错误( 我会立马修复

ModyQyW commented 1 year ago

我还以为是我哪里配置错了 😂

nonzzz commented 1 year ago

@ModyQyW 0.6.2 已恢复正常

ModyQyW commented 1 year ago

一切正常,非常感谢。