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

ERR_REQUIRE_ESM Problem #80

Closed
ghost opened this issue Jul 18, 2021 · 4 comments
Closed

ERR_REQUIRE_ESM Problem #80

ghost opened this issue Jul 18, 2021 · 4 comments

Comments

@ghost
Copy link

ghost commented Jul 18, 2021

This happened to me when i'm using mem in Typescript. Can anybody resolve this issue:

internal/modules/cjs/loader.js:1102
      throw new ERR_REQUIRE_ESM(filename, parentPath, packageJsonPath);
      ^

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: C:\Users\Tyo\Desktop\eemoji\node_modules\mem\dist\index.js
require() of ES modules is not supported.
require() of C:\Users\Tyo\Desktop\eemoji\node_modules\mem\dist\index.js from C:\Users\Tyo\Desktop\eemoji\dist\utils\Client.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from C:\Users\Tyo\Desktop\eemoji\node_modules\mem\package.json.
@fregante
Copy link
Collaborator

https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c

@ghost
Copy link
Author

ghost commented Jul 18, 2021

thank you for your response.

@noway
Copy link

noway commented Aug 29, 2021

Unfortunately, I can't use the package in React Native. There's no ESM support out of the box.

Repository owner locked and limited conversation to collaborators Aug 29, 2021
@fregante
Copy link
Collaborator

fregante commented Aug 29, 2021

Refer to https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c

There's nothing else to add here and the module will stay ESM-only. The previous version of mem can still be used as a CJS module like before.

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

No branches or pull requests

2 participants