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
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
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 codecompiled with babelcompiled with swcDue to this, the error
ReferenceError: Cannot access 'Example' before initializationhappens.The error would be fixed if the creation of the 'Example' property was done after declaring the class.
no errorconfig{ "$schema": "https://json.schemastore.org/swcrc", "jsc": { "target": "es2022", "experimental": { "keepImportAssertions": true }, "baseUrl": "./src", "keepClassNames": false, "paths": { "@config/*": ["config/*"], "@dtos/*": ["dtos/*"], "@jobs/*": ["jobs/*"], "@middlewares/*": ["middlewares/*"], "@modules/*": ["modules/*"], "@routes/*": ["routes/*"], "@shared/*": ["shared/*"], "@utils/*": ["utils/*"] }, "parser": { "syntax": "typescript", "tsx": false, "decorators": true, "dynamicImport": true }, "transform": { "legacyDecorator": true, "decoratorMetadata": true, "useDefineForClassFields": true }, "externalHelpers": false, "loose": true }, "module": { "type": "commonjs", "strict": true, "strictMode": true, "lazy": false, "noInterop": false, "resolveFully": false }, "minify": false }comand:
swc src --out-dir dist/. --copy-files --ignore **/*.spec.tsBeta Was this translation helpful? Give feedback.
All reactions