When importing libp2p in a TypeScript module, many of the exports seem to be missing but when using plain JS in an ESM module it works fine.
#!/usr/bin/env ts-node
import { createLibp2p } from "libp2p"; // "libp2p": "^0.38.0"
/*
SyntaxError: Named export 'createLibp2p' not found. The requested module 'libp2p' is a CommonJS module, which may not support all module.exports as named exports.
*/
#!/usr/bin/env ts-node
import Libp2p from "libp2p";
// [class Libp2p extends EventEmitter]
My .tsconfig.json:
{
"compilerOptions": {
"esModuleInterop": true,
"module": "ES2022",
"target": "ES2022"
},
"ts-node": {
"swc": true,
"esm": true
}
}
What is going on here? Shouldn’t the TS be getting complied down to ESM imports and therefore no different from the JS version?