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
{{ message }}
This repository has been archived by the owner on Sep 2, 2023. It is now read-only.
But, as far as I can tell, there's no way to write a synchronous CJS wrapper around an ESM library. CJS scripts can only import ESM with asynchronous dynamic import.
I believe I understand why require('./index.mjs') wouldn't match the CJS require semantics, but I think it should be possible in principle to implement a module.importSync() feature that would work like this:
This feature would be useful, because it would provide a path for a CJS library to port to ESM while preserving CJS semantics. A typical flow might be:
Pure CJS library
Add ESM wrapper and exports map in package.json
Port to ESM, add CJS wrapper, update exports map
The text was updated successfully, but these errors were encountered:
I think that your importSync would run into the same issues as “require of ESM” which has had a lot of discussion in this repo and a PR from @weswigham. See #454.
Today, it's straightforward to take a CJS library and add an ESM wrapper around it; this is recommended practice in https://github.com/nodejs/node/blob/master/doc/api/esm.md
But, as far as I can tell, there's no way to write a synchronous CJS wrapper around an ESM library. CJS scripts can only import ESM with asynchronous dynamic import.
I believe I understand why
require('./index.mjs')
wouldn't match the CJSrequire
semantics, but I think it should be possible in principle to implement amodule.importSync()
feature that would work like this:This feature would be useful, because it would provide a path for a CJS library to port to ESM while preserving CJS semantics. A typical flow might be:
exports
map inpackage.json
exports
mapThe text was updated successfully, but these errors were encountered: