Importing and module initialization is generally simple using JavaScript/TypeScript using either require
or import
. I'm having trouble running the basic example from the JS IPFS website to initialize ipfs
.
If I follow the general instructions I get an error: Module parse failed: Cannot use keyword 'await' outside an async function (6:13)
This is the critical code:
const IPFS = require('ipfs-core');
const ipfs = await IPFS.create();
If I follow the suggestion to place the ipfs
creation in an async
function I just delay the inevitable. If I call such a function twice I get an error from Unhandled Rejection (LockExistsError): Lock already being held for file: ipfs/repo.lock
. It seems I could create a hack to test whether ipfs
is created or not and initialize it global to a module as null, but that would still be a hack.
How should I implement or refactor const ipfs = await IPFS.create();
without error?