aws/glide-for-redis

NodeJS: CommonJS vs ECMA

Closed this issue · 2 comments

Describe the feature

The NodeJS package is currently built in ECMA, which makes it incompatible with a CommonJS project. https://github.com/aws/glide-for-redis/blob/main/node/npm/glide/tsconfig.json#L4

Use Case

Currently our project (who wants to use glide) is built like this :

{
  "compilerOptions": {
    "module": "commonjs",
    "moduleResolution": "node",
    "target": "es2020",
    "lib": [
      "es2020"
    ],
  },
}

So, we can't use this package due to our current configuration. It's also impossible for us to change the way we build our project, because of many packages used.

 ealen…/web-services/core/core on  master +252 -1 [!] is 📦 v0.0.1 via  v20.11.1 on ☁️  saml (us-east-1) [X] 祥14s 
❯ npm run start

> project@0.0.1 start
> node --require dotenv/config dist/main.js

/home/ealen/code/web-services/core/core/dist/main.js:4
const glide_for_redis_1 = require("@aws/glide-for-redis");
                          ^

Error [ERR_REQUIRE_ESM]: require() of ES Module /home/ealen/code/web-services/core/core/node_modules/@aws/glide-for-redis/build-ts/index.js from /home/ealen/code/web-services/core/core/dist/main.js not supported.
index.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules.
Instead either rename index.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "module" to "type": "commonjs" in /home/ealen/code/web-services/core/core/node_modules/@aws/glide-for-redis/package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).

    at Object.<anonymous> (/home/ealen/code/web-services/core/core/dist/main.js:4:27) {
  code: 'ERR_REQUIRE_ESM'
}

Node.js v20.11.1

Proposed Solution

Is it possible to create "hybrid" modules that support commonJS and ECMA ?

Other Information

No response

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

Client version used

0.2.0

Environment details (OS name and version, etc.)

Ubuntu 22.04.2 LTS - Node v20.11.1

Thanks @Ealenn ,

This feature was not planned. We will be happy for contribution, otherwise we’ll update you once the feature is implemented and released. We will be happy to work with you together and further discuss it.