The current @swc-node/register/esm loader does not respect the SWCRC environment variable. This is due to the condition for setting swcRegisterConfig only applying to the sync transform version.
This PR fixes that, and also fixes module being overridden by "commonjs" when SWCRC environment variable is specified, which causes files being transformed by register/esm to be loaded as CommonJS which causes errors such as these:
server | file:///app/apps/backend/src/app.ts:2
server | Object.defineProperty(exports, "__esModule", {
server | ^
server |
server | ReferenceError: exports is not defined in ES module scope
server | at file:///app/apps/backend/src/app.ts.mjs:2:23
server | at ModuleJob.run (node:internal/modules/esm/module_job:194:25)
server |
The current
@swc-node/register/esm
loader does not respect theSWCRC
environment variable. This is due to the condition for settingswcRegisterConfig
only applying to the synctransform
version.This PR fixes that, and also fixes
module
being overridden by"commonjs"
whenSWCRC
environment variable is specified, which causes files being transformed byregister/esm
to be loaded as CommonJS which causes errors such as these: