Closed bitjson closed 2 years ago
Ah, I also added 'import/extensions': ['error', { js: 'always' }],
in .eslintrc.js
; that makes it easier to notice when a rogue import would break esm imports at runtime.
A project using this PR: https://gitlab.com/GeneralProtocols/anyhedge/library/-/merge_requests/193
Node's ESM import requires file extensions for all imports: https://nodejs.org/api/esm.html#mandatory-file-extensions. Without the
.js
extensions, a runtime error is thrown whencashscript
is imported by esm projects.This also updates
electrum-cash
, where some interfaces have changed (and if another package tries to share configuration withElectrumNetworkProvider
, they'll get type errors, as this one is more restrictive).Finally, the explicit exporting of the network classes (in
src/index.ts
) solves an issue that esm dependents encounter:The requested module 'cashscript' does not provide an export named 'ElectrumNetworkProvider'
.(And if you're interested in migrating to ESM, hopefully this gets you a lot closer!)