Replies: 4 comments
-
I'm nearly 50/50 on this. Converting existing projects from CJS to ESM always seems to surface all sorts of inescapable dependency issues, but I think that |
Beta Was this translation helpful? Give feedback.
-
Last week I migrated Juno libraries to Esm only. It actually took quite some effort because I had to find ways to polyfill agent-js CJS and how to properly set my libraries. So in that sense, if other devs also want to use Esm on NodeJS, I would say yes that would be a good thing because it would ease their life. Voted "Yes" for above reason and because I use Esm in my scripts and personal code but, can continue to live with Cjs. Note: if we migrate to Esm, we have to ensure that the package will still work in Web Workers - notably use in NNS-dapp that way. |
Beta Was this translation helpful? Give feedback.
-
I voted no because I think the ecosystem is not quite there yet in terms of ESM support. There's nothing worse than wanting to upgrade a library, only to discover it has dropped support for something you need and now have to jump through a whole series of hoops to get it working with the build system. Also worth noting is that some setups have different build systems for the app itself and its tests, which can exaggerate this issue. |
Beta Was this translation helpful? Give feedback.
-
I'm leaving this up for longer - 10 votes is definitely not a representative sample. I'll be sticking with commonjs unless I really feel like there's a mandate for ESM |
Beta Was this translation helpful? Give feedback.
-
With a large set of changes to Agent-JS on this branch, it includes an overhaul to the codebase that enables properly generating ECMAScript Modules for the first time.
As it stands, attempting to generate both ESM and CJS fails to account for some configurations. CJS may work normally for some node versions, but not with TypeScript. I also have noticed that types can get confused between CJS and ESM when CJS is not the default module type. Given this complexity, and that these changes will be breaking anyway, should we deprecate CommonJS?
Some consequences of this in your projects may be:
"type": "module"
inpackage.json
if you aren't already using itimport {HttpAgent} from '@dfinity/agent'
toconst {HttpAgent} = await import('@dfinity/agent')
10 votes ·
Beta Was this translation helpful? Give feedback.
All reactions