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

Error [ERR_REQUIRE_ESM]: require() of ES Module not supported #613

Open
eodeluga opened this issue Feb 12, 2024 · 2 comments
Open

Error [ERR_REQUIRE_ESM]: require() of ES Module not supported #613

eodeluga opened this issue Feb 12, 2024 · 2 comments

Comments

@eodeluga
Copy link

// test.ts
import unleet from '@cityssm/unleet'

unleet('b@d w0rd')

If I run either yarn ts-node test.ts or yarn tsc test.ts && node test.js I get the following error:

var unleet_1 = require("@cityssm/unleet");
               ^

Error [ERR_REQUIRE_ESM]: require() of ES Module /home/eodeluga/src/test/node_modules/@cityssm/unleet/index.js from /home/eodeluga/test/test.js not supported.
Instead change the require of index.js in /home/eodeluga/src/test/test.js to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (/home/eodeluga/src/test/test.js:3:16) {
  code: 'ERR_REQUIRE_ESM'
}

Node.js v18.18.0
@dangowans
Copy link
Member

Thanks for reaching out @eodeluga .

It looks like your TypeScript code, when compiled to JavaScript, ends up using require to import the module. require is not supported by unleet.

If your project allows, consider updating it to target a new version of JavaScript.

@eodeluga
Copy link
Author

Thank you.

Only way I could solve this is by using tsx instead tsc.

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

No branches or pull requests

2 participants