digitalbazaar / jsonld.js

A JSON-LD Processor and API implementation in JavaScript
https://json-ld.org/
Other
1.65k stars 195 forks source link

[ERR_REQUIRE_ESM]: require() of ES Module ky-universal from http-client\main.js not supported. #469

Open grenik opened 2 years ago

grenik commented 2 years ago

Because of security issue with node-fetch I needed to update ky-universal to 0.10.0 (issue)

Once I did this, I got the following error:

C:\Users\me\git\my_code\node_modules\@digitalbazaar\http-client\main.js:1
    Error [ERR_REQUIRE_ESM]: require() of ES Module C:\Users\me\git\my_code\node_modules\ky-universal\index.js from C:\Users\me\git\my_code\node_modules\@digitalbazaar\http-client\main.js not supported.
    Instead change the require of index.js in C:\Users\me\git\my_code\node_modules\@digitalbazaar\http-client\main.js to a dynamic import() which is available in all CommonJS modules.
        at Object.<anonymous> (C:\Users\me\git\my_code\node_modules\@digitalbazaar\http-client\main.js:1)
        at Generator.next (<anonymous>)

      at Object.<anonymous> (node_modules/@digitalbazaar/http-client/index.js:8:18)
      at Object.<anonymous> (node_modules/jsonld/lib/documentLoaders/node.js:12:22)
      at Object.<anonymous> (node_modules/jsonld/lib/platform.js:6:20)
      at Object.<anonymous> (node_modules/jsonld/lib/jsonld.js:37:18)
      at Object.<anonymous> (node_modules/jsonld/lib/index.js:8:18)
      at Object.<anonymous> (utils/my_code_where_I_require_jsonld.js:1513:26)

My package.json (relevant parts only):

{
  "dependencies": {
    "jsonld": "^5.2.0"
  },
  "overrides": {
    "ky-universal": "^0.10.0",
    "ky": "^0.26.0"
  }
}

In my code, I do:

require("jsonld");

Tried with node 14 & 16

I've created https://github.com/digitalbazaar/http-client/issues/17 but after some investigation it looks like it is more relevant here, since http-client uses import and require is used here: https://github.com/digitalbazaar/jsonld.js/blob/20e2286d198ce7d376320306f9df3667f48a4544/lib/documentLoaders/node.js#L12