Wondering if dynamic imports (eg. import(specifier)) can be transformed to check for the __esModule property on the imported module in case it's ESM to CJS transformed.
Currently, when transforming a ESM file to CJS via Transform API, import statements are transformed to use require() and wrapped in __toESM. However, dynamic imports are not transformed.
This leads to a discrepancy in what's exported by the module.
Feature request
Wondering if dynamic imports (eg.
import(specifier)
) can be transformed to check for the__esModule
property on the imported module in case it's ESM to CJS transformed.Before
After
Problem
Currently, when transforming a ESM file to CJS via Transform API,
import
statements are transformed to userequire()
and wrapped in__toESM
. However, dynamic imports are not transformed.This leads to a discrepancy in what's exported by the module.
esm.js
index.js
Expected behavior
Since import statements are transformed to interop with CJS-transformed ESM files, I would also expect the dynamic imports to as well: