Skip to content

Run time error in cjs compiled code due to default import #154

Description

@MichelSc

Hi! 👋

Firstly, thanks for your work on this project! 🙂

I use ldo version 1.0.0-alpha 51 with cjs modules.

I get a run-time error at this line, when calling jsonldDatasetProxy:

const proxyBuilder = jsonldDatasetProxy(this, shapeType.context);

This is the error:

_ldo_jsonld_dataset_proxy.default is not a function

The error is caused by the __toESM helper, in the cjs compiled code, that substitues in the exported structure the default member by the full package.

Not sure the bug is in the source code or in the compilation.
But using a named import instead of the default import at

import jsonldDatasetProxy from "@ldo/jsonld-dataset-proxy";
will probably solve the problem.

In the mean time see the patch here below.

Today I used patch-package to patch @ldo/ldo@1.0.0-alpha.51 for the project I'm working on.

Here is the diff that solved my problem:

diff --git a/node_modules/@ldo/ldo/dist/LdoDataset.cjs b/node_modules/@ldo/ldo/dist/LdoDataset.cjs
index 1a1d82d..47be7cd 100644
--- a/node_modules/@ldo/ldo/dist/LdoDataset.cjs
+++ b/node_modules/@ldo/ldo/dist/LdoDataset.cjs
@@ -3,7 +3,7 @@ const require_LdoBuilder = require("./LdoBuilder.cjs");
 const require_LdoTransactionDataset = require("./LdoTransactionDataset.cjs");
 let _ldo_subscribable_dataset = require("@ldo/subscribable-dataset");
 let _ldo_jsonld_dataset_proxy = require("@ldo/jsonld-dataset-proxy");
-_ldo_jsonld_dataset_proxy = require_runtime.__toESM(_ldo_jsonld_dataset_proxy, 1);
+//_ldo_jsonld_dataset_proxy = require_runtime.__toESM(_ldo_jsonld_dataset_proxy, 1);
 //#region src/LdoDataset.ts
 /**
 * @category Getting an LdoDataset

This issue body was partially generated by patch-package.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions