ethereumjs-monorepo icon indicating copy to clipboard operation
ethereumjs-monorepo copied to clipboard

Monorepo: Distribute modules with esm as well

Open kumavis opened this issue 4 years ago • 5 comments

since the packages are authored as typescript esm it should be easy to distribute as esm in addition to cjs

kumavis avatar Sep 10 '21 00:09 kumavis

eg @ethereumjs/tx only provides a "main" which points to the cjs build https://npmfs.com/package/@ethereumjs/tx/3.3.0/package.json#L16

kumavis avatar Sep 10 '21 00:09 kumavis

Some context on this, here is the Node.js ESM documentation.

Some articles on possible approaches:

Related issue: #978

What do you guys think, might be a good time to prioritize a bit on this? (@kumavis thanks for the suggestion)

holgerd77 avatar Sep 10 '21 07:09 holgerd77

Some more resources, more specifically for TypeScript:

https://github.com/gfmio/typescript-esm-cjs-hybrid-example

https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-5.html#ecmascript-module-support-in-nodejs

ryanio avatar Oct 11 '21 10:10 ryanio

I might be able to take this on, depending on how my experiments with the portal network module go. I'm using Rollup to package for esm and commonjs there though it's not seamless yet.😬

acolytec3 avatar Oct 12 '21 18:10 acolytec3

This should be delayed until node.js drops support for v14, which is 2023+. The constraint list:

It is not possible to use dynamic requires same code to be used in node.js and browser (NPM etc). I'm talking about this pattern:

export const crypto: { node?: any; web?: any } = (() => {
  const webCrypto = typeof self === 'object' && 'crypto' in self ? self.crypto : undefined;
  const nodeRequire = typeof module !== 'undefined' && typeof require === 'function';
  return {
    node: nodeRequire && !webCrypto ? require('crypto') : undefined,
    web: webCrypto,
  };
})();

paulmillr avatar Nov 23 '21 04:11 paulmillr

Will be included in v7.

acolytec3 avatar May 22 '23 16:05 acolytec3