zhangyuang / ssr

A most advanced ssr framework support React17/React18/Vue2/Vue3 on Earth that implemented serverless-side render specification.
http://doc.ssr-fc.com/
MIT License
2.59k stars 283 forks source link

vite打包出现'Uncaught TypeError: Cannot read properties of undefined (reading 'exports')' #159

Closed DCLangX closed 2 years ago

DCLangX commented 2 years ago

详细描述你的问题

大佬,又是我,前天更新了一下依赖,开发模式也是运行正常,,用vite打包出来的文件发现报了个错 image 经过反复删减,最终发现是我写的axios相关代码打包后报错了,,复制出来在vue3-nestjs-ssr示例测试,可以复现

期望的结果

当前使用的版本

6.1.49

复现仓库地址

代码: https://github.com/DCLangX/testSSRError 部署预览: http://home.niye.vip:3000/

你本人对问题可能的原因判断(如果你能大概判断的话)

可能跟我创建了两个axios实例有关,分别在页面和vuex里有引入两个实例的接口,, image 具体细节可以看这个提交 https://github.com/DCLangX/testSSRError/commit/b120fab8b83646841423b77de337582fd0628dfb

zhangyuang commented 2 years ago

晚点看看

发自我的iPhone

------------------ 原始邮件 ------------------ 发件人: 爱吃薯片的内存条 @.> 发送时间: 2022年1月24日 10:37 收件人: zhangyuang/ssr @.> 抄送: Subscribed @.***> 主题: Re: [zhangyuang/ssr] vite打包出现'Uncaught TypeError: Cannot read properties of undefined (reading 'exports')' (Issue #159)

详细描述你的问题

大佬,又是我,前天更新了一下依赖,开发模式也是运行正常,,用vite打包出来的文件发现报了个错

经过反复删减,最终发现是我写的axios相关代码打包后报错了,,复制出来在vue3-nestjs-ssr示例测试,可以复现 代码: https://github.com/DCLangX/testSSRError

期望的结果

当前使用的版本

不要贴 package.json 用 yarn list "ssr*" 来查看版本。同时建议熟读semver 规则并且知道怎么安装最新依赖!

复现仓库地址

超过一行代码能描述的问题必须提供复现地址, 用默认的 example 给最简单的复现代码不要给包含着一堆业务代码的仓库

你本人对问题可能的原因判断(如果你能大概判断的话)

— Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android. You are receiving this because you are subscribed to this thread.Message ID: @.***>

zhangyuang commented 2 years ago

fix by https://github.com/zhangyuang/ssr/commit/e034b6b1d1c8d2e25e1b2a5ca08e82c6d2af9823

DCLangX commented 2 years ago

fix by e034b6b

昨天的错不报了,不过又出来了新的错( ̄▽ ̄)",这次好像是打包vant出的错 image 还是这个复现地址: https://github.com/DCLangX/testSSRError 部署预览: http://home.niye.vip:3000/

我在昨天的页面加了两个按钮,axios加了一个弹窗提醒 https://github.com/DCLangX/testSSRError/commit/98ca6d6cac7912d32b1fb667c0a0f0362a3c272e

DCLangX commented 2 years ago

fix by e034b6b

昨天的错不报了,不过又出来了新的错( ̄▽ ̄)",这次好像是打包vant出的错 image 还是这个复现地址: https://github.com/DCLangX/testSSRError 部署预览: http://home.niye.vip:3000/

我在昨天的页面加了两个按钮,axios加了一个弹窗提醒 DCLangX/testSSRError@98ca6d6

@zhangyuang 大佬,我后面这个报错,有头绪吗

zhangyuang commented 2 years ago

已经修复了啊 是因为你在store里面引入了页面组件里用到的文件导致循环依赖

发自我的iPhone

------------------ 原始邮件 ------------------ 发件人: 爱吃薯片的内存条 @.> 发送时间: 2022年1月27日 13:34 收件人: zhangyuang/ssr @.> 抄送: yuuang @.>, Mention @.> 主题: Re: [zhangyuang/ssr] vite打包出现'Uncaught TypeError: Cannot read properties of undefined (reading 'exports')' (Issue #159)

fix by e034b6b

昨天的错不报了,不过又出来了新的错( ̄▽ ̄)",这次好像是打包vant出的错 还是这个复现地址: https://github.com/DCLangX/testSSRError 部署预览: http://home.niye.vip:3000/

我在昨天的页面加了两个按钮,axios加了一个弹窗提醒 @.***

@zhangyuang 大佬,我后面这个报错,有头绪吗

— Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android. You are receiving this because you were mentioned.Message ID: @.***>

DCLangX commented 2 years ago

昨天更到6.1.55,试了报错了,刚刚又试了下,确实还是报了Uncaught ReferenceError: Cannot access 'xu' before initialization,难道是又是苹果跟windows打包出来有差异,我试下苹果

DCLangX commented 2 years ago

试了下苹果,确实也是一样 image

zhangyuang commented 2 years ago

先用webpack构建吧,你这个场景太复杂了,涉及到了很多循环依赖。

zhangyuang commented 2 years ago

支持 ssr build --vite --legacy 关闭 manualChunks 功能用以获得稳定的构建产物,但会带来一定的性能损失,视情况开启https://github.com/zhangyuang/ssr/commit/8f5d9dac405b2a998d1e22d4d1484a6d544697ae

DCLangX commented 2 years ago

👏有点拼啊,大晚上还在改代码,赞助一个鸡腿🍗

zhangyuang commented 2 years ago

更新了6.1.56,可以再试试

DCLangX commented 2 years ago

哇,可以了,,上面的测试代码加不加--legacy都能通过,不过项目里还得加--legacy才不报错,看来这个manualChunks我能提一打的issue,哈哈🤡

zhangyuang commented 2 years ago

legacy我又移除了 最新的方案应该不需要legacy了 还有问题给复现

发自我的iPhone

------------------ 原始邮件 ------------------ 发件人: 爱吃薯片的内存条 @.> 发送时间: 2022年1月28日 17:30 收件人: zhangyuang/ssr @.> 抄送: yuuang @.>, Mention @.> 主题: Re: [zhangyuang/ssr] vite打包出现'Uncaught TypeError: Cannot read properties of undefined (reading 'exports')' (Issue #159)

哇,可以了,,上面的测试代码加不加--legacy都能通过,不过项目里还得加--legacy才不报错,看来这个manualChunks我能提一打的issue,哈哈🤡

— Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android. You are receiving this because you were mentioned.Message ID: @.***>

DCLangX commented 2 years ago

提交了新的错误复现 image

还是这个复现仓库: https://github.com/DCLangX/testSSRError 部署预览: http://home.niye.vip:3000/

这次主要是把页面取store数据封装了hooks,然后又加了const router = useRouter()和const route = useRoute()就出现了循环依赖