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

[Bug]: 升级到 v0.4.5 本地运行正常,线上运行报错 #5760

Closed
iwtem opened this issue Feb 23, 2024 · 17 comments
Closed

[Bug]: 升级到 v0.4.5 本地运行正常,线上运行报错 #5760

iwtem opened this issue Feb 23, 2024 · 17 comments
Labels
bug Something isn't working rsbuild rsbuild related upstream

Comments

@iwtem
Copy link

iwtem commented Feb 23, 2024

Version

System:
    OS: macOS 14.2.1
    CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 8.38 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Browsers:
    Chrome: 122.0.6261.57
    Safari: 17.2.1

Details

本地开发均正常,升级到测试环境会有报错,部分页面显示正常,正常的应该是未加载下面的这个文件。

image

Reproduce link

CodeSandbox 复现链接

Reproduce Steps

如果在项目中引用 slate-history 这个包,就会出现本地开发正常,打包部署错误的问题

使用 rsbuild dev 运行正常

使用 rsbuild preview 报错

image
@iwtem
Copy link
Author

iwtem commented Feb 23, 2024

从 0.3.5 升级到的 0.4.5

@chenjiahan
Copy link
Member

能否依次降级版本试一下,看看具体是哪一个小版本开始出现的这个问题

@iwtem
Copy link
Author

iwtem commented Feb 23, 2024

能否依次降级版本试一下,看看具体是哪一个小版本开始出现的这个问题

我先这么试下

@iwtem
Copy link
Author

iwtem commented Feb 23, 2024

  1. 先降到了 0.4.40.4.3 都是上面的错误;

  2. 再降到了 0.4.00.3.11 报了新的错误:
    企业微信截图_168515e0-8834-4d07-b13a-45d6a413bde6

  3. 直接降到 0.3.5 正常,再升级到 0.3.8 不正常,同 2,再降级到 0.3.7 正常

@chenjiahan
Copy link
Member

可能是 0.4.1 版本升级了 Rspack v0.5.4 导致的,能否试一下 0.4.1 版本是哪一个报错

@chenjiahan
Copy link
Member

另外看看能提供一个最小复现 demo 不,方便我们定位问题

@iwtem
Copy link
Author

iwtem commented Feb 23, 2024

可能是 0.4.1 版本升级了 Rspack v0.5.4 导致的,能否试一下 0.4.1 版本是哪一个报错

0.4.1 build 后的 preview
image

@iwtem
Copy link
Author

iwtem commented Feb 23, 2024

另外看看能提供一个最小复现 demo 不,方便我们定位问题

这个也是在项目里面跑的,小的 demo 不知道能不能复现,等有空了我试下

@chenjiahan
Copy link
Member

你看看这个错误具体是哪一段代码引起的,是否存在代码写法问题:

image

@iwtem
Copy link
Author

iwtem commented Feb 23, 2024

0.3.7 及以下正常
0.3.8 及以后开始报错 require is not defined
0.4.1 开始报 ChunkLoadError

代码都是一样的,感觉不是代码的问题,是不是打包机制哪里发生了变化,看了你们的升级日志都是升级了 rspack 开始报的错

@chenjiahan chenjiahan transferred this issue from web-infra-dev/rsbuild Feb 23, 2024
@chenjiahan
Copy link
Member

我先 transfer issue 到 Rspack 仓库来跟进

@chenjiahan chenjiahan added bug Something isn't working rsbuild rsbuild related labels Feb 23, 2024
Copy link
Contributor

Hello @iwtem, sorry we can't investigate the problem further without reproduction demo, please provide a repro demo by forking rspack-repro, or provide a minimal GitHub repository by yourself. Issues labeled by need reproduction will be closed if no activities in 14 days.

@iwtem
Copy link
Author

iwtem commented Mar 4, 2024

复现链接及步骤如上。

看了下打包后的产物:
image

源代码:
image

image

这是 slate-history 地址:https://github.com/ianstormtaylor/slate/tree/main/packages/slate-history

@martijn-veenstra
Copy link

Im facing similar issues. My issue seem to refer to an emotion import, but I doubt that it's the issue

@xc2
Copy link
Collaborator

xc2 commented Mar 5, 2024

minimal reproducing: https://github.com/xc2/issue-5760

happens only when mangle is on


update: it's a hoist_props related bug.

@xc2 xc2 added the pending triage The issue/PR is currently untouched. label Mar 7, 2024
@xc2
Copy link
Collaborator

xc2 commented Mar 8, 2024

@iwtem @martijn-veenstra and everyone who searched for this problem, here is a workaround:

try any of minify options below:

  1. { compress: { passes: 2 } }
  2. { compress: { hoist_props: false } }
  3. { mange: false }

here's guides to modify minify options:


it is an upstream bug and can be skip by options.

it is confirmed that swc has been fixed this bug in 0.192.2 swc-project/swc#8593

rspack needs to bump swc_ecma_minifier to fix it.

@xc2 xc2 added upstream and removed pending triage The issue/PR is currently untouched. labels Mar 8, 2024
@iwtem
Copy link
Author

iwtem commented Mar 12, 2024

方案1、2、3 调整后都可以正常运行了,方案 3 会增大 20% 的产物体积,建议使用 1、2方案

@iwtem iwtem closed this as completed Mar 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working rsbuild rsbuild related upstream
Projects
None yet
Development

No branches or pull requests

4 participants