Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NodeJS: CommonJS vs ECMA #1116

Closed
1 of 2 tasks
Ealenn opened this issue Mar 13, 2024 · 2 comments
Closed
1 of 2 tasks

NodeJS: CommonJS vs ECMA #1116

Ealenn opened this issue Mar 13, 2024 · 2 comments
Assignees
Labels
Milestone

Comments

@Ealenn
Copy link

Ealenn commented Mar 13, 2024

Describe the feature

The NodeJS package is currently built in ECMA, which makes it incompatible with a CommonJS project. https:/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

> [email protected] 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

@shachlanAmazon
Copy link
Contributor

@avifenesh PTAL

@asafpamzn
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants