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]: Cannot access '[class x]' before initialization. when rspack handles class dependencies, the scope elevation does not take effect for the class. #7122

Open
1yasa opened this issue Jul 11, 2024 · 6 comments
Assignees
Labels
bug Something isn't working same as webpack The behavior is the same as Webpack

Comments

@1yasa
Copy link

1yasa commented Jul 11, 2024

System Info

System:
OS: macOS 14.4
CPU: (32) x64 13th Gen Intel(R) Core(TM) i9-13900KF
Memory: 12.73 GB / 32.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 21.6.1 - /usr/local/bin/node
npm: 10.2.4 - /usr/local/bin/npm
pnpm: 9.4.0 - /usr/local/bin/pnpm
Watchman: 2024.06.10.00 - /usr/local/bin/watchman

Details

rspack build output used in app error:
截屏2024-07-11 18 17 46

location for error code:
截屏2024-07-11 18 17 58

class dependencie [LexicalNode] defind in the last bottom:
截屏2024-07-11 18 18 52

rollup build output [LexicalNode] in the top(before used):
截屏2024-07-11 18 19 54

I tried all possible configurations of swc and rspack, and finally concluded that this issue might be due to the omission of some scenarios of class scope hoisting.

It could also be a circular dependency causing the scope to be hoisted incorrectly.

Reproduce link

https://github.com/openages/lexical

Reproduce Steps

pnpm run rspack for rspack build output.

pnpm run build for rollup build output.

use "lexical":"workspace:*" in the monorepo/packages/app.

https://lexical.dev/docs/getting-started/quick-start

@1yasa 1yasa added bug Something isn't working pending triage The issue/PR is currently untouched. labels Jul 11, 2024
@1yasa
Copy link
Author

1yasa commented Jul 11, 2024

By the way, this also may cause by pure esm(rspack handle pure esm is experimental).

@1yasa
Copy link
Author

1yasa commented Jul 11, 2024

Reproduce when use rollup(export LexicalNode instead of export type LexicalNode):

截屏2024-07-11 19 46 53

So question is, why rspack treat export type LexicalNode as a actually export, the rollup handle this case is right.

@1yasa
Copy link
Author

1yasa commented Jul 11, 2024

截屏2024-07-11 20 19 18

Tested export order, that may cause output same error, fixed by export * from ''.

But rspack still scope to be hoisted incorrectly.

@ahabhgk ahabhgk self-assigned this Jul 13, 2024
@ahabhgk ahabhgk added same as webpack The behavior is the same as Webpack and removed pending triage The issue/PR is currently untouched. labels Jul 13, 2024
@1yasa
Copy link
Author

1yasa commented Jul 16, 2024

@ahabhgk "same as webpack" It means that webpack is the same, so will it not be fixed?

@ahabhgk
Copy link
Collaborator

ahabhgk commented Jul 17, 2024

No, it means we will fix it for both rspack and webpack

@ahabhgk
Copy link
Collaborator

ahabhgk commented Jul 17, 2024

This is caused by circular imports and the case is very complex, so we may need more time to find the root issue and then fix it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working same as webpack The behavior is the same as Webpack
Projects
None yet
Development

No branches or pull requests

2 participants