js-multiformats icon indicating copy to clipboard operation
js-multiformats copied to clipboard

Document ESM and consequent node version requirements

Open alexjg opened this issue 4 years ago • 1 comments

I just ran into an issue where I was using an older version of Node (12.16.1) and getting a "Cannot find module 'multiformats'" error after installation. This seems to be because of the use of ESM modules, which are only be supported in the latest version of node. It's probably worth adding a note about this to the README as otherwise it's very difficult to debug.

alexjg avatar Sep 08 '20 13:09 alexjg

I experienced the same issue. The workaround that I found is the following:

Importing in Node (version>12):

// @ts-ignore
import multiformats from 'multiformats/basics'
// @ts-ignore
import legacy from 'multiformats/legacy'

Importing in jest tests:

import basicsImport from 'multiformats/cjs/src/basics-import.js'
import legacy from 'multiformats/cjs/src/legacy.js'

ESM modules are not supported in Jest as well. This is the link the reference.

simonovic86 avatar Sep 08 '20 13:09 simonovic86