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
It occurs to me that someone could write a package that uses the module customization hooks to detect when someone does require of an ESM package and then that package gets transpiled into CommonJS on demand. So instead of pinning node-fetch to an old version, say, you could use the latest version and have --import transpile-esm-dependencies automatically convert it on the fly into a sync CommonJS version that an app can use. This would solve one of the more frustrating annoyances that users have faced since the ESM migration began.
This isn’t quite what Bun does automatically with its require(esm), since it transpiles everything into ESM that it mostly runs sync; but it’s the same from the perspective of the user. What I’m describing is essentially what Webpack does when you tell it to transpile your node_modules or certain packages inside node_modules.
Does a library exist to do what I’m suggesting here? If so, or if someone wants to write one, we could maybe mention it from the Node docs. I know we’re reluctant to recommend particular libraries in our docs, but this problem comes up so often that it would be nice if we could tell users how to solve it. I don’t foresee Node having some built-in solution; we’re not going to ship a bundler within Node anytime soon. But I think we should be able to get consensus on providing some guidance to users for common issues like this, as well as guiding them on how to get runtime TypeScript transpilation working.
The text was updated successfully, but these errors were encountered:
It occurs to me that someone could write a package that uses the module customization hooks to detect when someone does
require
of an ESM package and then that package gets transpiled into CommonJS on demand. So instead of pinningnode-fetch
to an old version, say, you could use the latest version and have--import transpile-esm-dependencies
automatically convert it on the fly into a sync CommonJS version that an app can use. This would solve one of the more frustrating annoyances that users have faced since the ESM migration began.This isn’t quite what Bun does automatically with its
require(esm)
, since it transpiles everything into ESM that it mostly runs sync; but it’s the same from the perspective of the user. What I’m describing is essentially what Webpack does when you tell it to transpile yournode_modules
or certain packages insidenode_modules
.Does a library exist to do what I’m suggesting here? If so, or if someone wants to write one, we could maybe mention it from the Node docs. I know we’re reluctant to recommend particular libraries in our docs, but this problem comes up so often that it would be nice if we could tell users how to solve it. I don’t foresee Node having some built-in solution; we’re not going to ship a bundler within Node anytime soon. But I think we should be able to get consensus on providing some guidance to users for common issues like this, as well as guiding them on how to get runtime TypeScript transpilation working.
The text was updated successfully, but these errors were encountered: