How to avoid the error "Cannot access property before initialization" when compiling with commonjs? #8578
Replies: 1 comment
-
Please take a look at #5205 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I saw some issues similar to this one #7005 where it could not access the X class before its initialization and were evaluated as
not a bug
.How could I avoid this? Are there any settings I may have forgotten?
It's necessary to use commonjs because a lot of libraries have not support for esmodules.
This is an example of whats is happening:
Original code
compiled with babel
compiled with swc
Due to this, the error
ReferenceError: Cannot access 'Example' before initialization
happens.The error would be fixed if the creation of the 'Example' property was done after declaring the class.
no error
config
comand:
swc src --out-dir dist/. --copy-files --ignore **/*.spec.ts
Beta Was this translation helpful? Give feedback.
All reactions