Closed jandrieu closed 1 year ago
I assume you mean v16.13.1.
It does look like examples need some work. I think those examples may have come from code run through 'webpack' and/or 'esm'. One solution is to jump through an 'esm' hoop first:
index.js:
require = require('esm')(module);
module.exports = require('./main.js');
and in main.js:
import { encode } from '@digitalbazaar/cborld';
const jsonldDocument = {
'@context': 'https://www.w3.org/ns/activitystreams',
type: 'Note',
summary: 'CBOR-LD',
content: 'CBOR-LD is awesome!'
};
// FIXME create documentLoader
async function main() {
// encode a JSON-LD Javascript object into CBOR-LD bytes
const cborldBytes = await encode({ jsonldDocument, documentLoader });
console.log(cborldBytes);
}
main();
You'll need to create a documentLoader that can handle contexts you use. (https://github.com/digitalbazaar/cborld/issues/54)
The module part will be fixed at some point. It's a bit tricky to handle CommonJS and ESM modules. I have a possible fix, but it needs to be vetted and then applied on a whole bunch of modules all at once so they all play together nicely. In this case, it would at least need to be applied to base58-universal dependency too. If you're interested in exploring that, I can show you the patches, but the above hack is easier for now. You could also switch to CommonJS and use require
instead.
If you just wanted to see the encoded output, you might consider the in-progress branch of cborld-cli tool.
We ran into the same issue. Is there any executable Node JS example that we can just test and run?
We ran into the same issue. Is there any executable Node JS example that we can just test and run?
Hey Oliver, I think your best bet is to use the DCC fork of this lib (https://github.com/digitalcredentials/cborld), which we made work with TS and ReactNative. We use it in our VPQR fork (which creates CBOR-LD QR codes from VPs), so that might be your best bet of using executable Node/TS-compatible code: https://github.com/digitalcredentials/vpqr/blob/main/test/mock-data.js / https://github.com/digitalcredentials/vpqr/blob/main/test/vpqr.spec.js
Closing as this library no longer uses esm.js
and is a proper ESM library.
I've tried running the examples, but can get neither encode nor decode to work.
I set up a new npm init and installed @digitalbazaar/cborld.
When I tried the first code,
Unfortunately, that complained about the use of import outside a module
If I add "type"="module" in my package.json, I get passed that error, only to get this one:
FWIW, I tried this alternative import and it didn't work.
On a lark, I tried the "type":"module" hack in the cborld package.json, I get a different error:
Any suggestions?
p.s. This was on a windows bash shell, running node v16.123.1