You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I came up with a super easy way of doing this instead of going "syntheticNamedExports". To be clear I just want to replicate the node17 behavior: use cjs-module-lexer to support partial of the cjs modules. The transformed module will be like:
varexports={},module={exports}// have to use { block } to prevent names conflict{// original code}exportdefaultmodule.exports// analyzed possible named exportsexportvaruseState=module.exports.useState...
The downside is obvious: some modules will cause error at runtime when it doesn't follow the pattern. But the advantage is we can reduce some verbosing code about __commonJS. I can make this transformation optional.
Those requires still need the trick in this repo. But I want to add additional info here:
try{require("x")}catch{}
Code like this won't be transformed to import statement because esbuild allowed this pattern and it won't warn about it. Frankly speaking, even "require is undefined" won't cause error at runtime when it was caught like this.
The text was updated successfully, but these errors were encountered:
I came up with a super easy way of doing this instead of going "syntheticNamedExports". To be clear I just want to replicate the node17 behavior: use cjs-module-lexer to support partial of the cjs modules. The transformed module will be like:
The downside is obvious: some modules will cause error at runtime when it doesn't follow the pattern. But the advantage is we can reduce some verbosing code about
__commonJS
. I can make this transformation optional.Those
require
s still need the trick in this repo. But I want to add additional info here:Code like this won't be transformed to
import
statement because esbuild allowed this pattern and it won't warn about it. Frankly speaking, even "require is undefined" won't cause error at runtime when it was caught like this.The text was updated successfully, but these errors were encountered: