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

Get error message: Error [ERR_REQUIRE_ESM]: Must use import to load ES Module while import os-locale #51

Closed
LjjStar opened this issue Sep 7, 2021 · 6 comments

Comments

@LjjStar
Copy link

LjjStar commented Sep 7, 2021

Does anyone encounter the below issue while using the packag os-locale?

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: C:\Users\Admin\Desktop\node_modules\os-locale\index.js
require() of ES modules is not supported.
require() of C:\Users\Admin\Desktop\node_modules\os-locale\index.js from C:\Users\Admin\Desktop\xxxx\lib\helper\utils.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\Admin\Desktop\node_modules\os-local

@LjjStar
Copy link
Author

LjjStar commented Sep 7, 2021

node version: 14.17.4

@LjjStar LjjStar changed the title Get error message while import os-locale Get error message: Error [ERR_REQUIRE_ESM]: Must use import to load ES Module while import os-locale Sep 7, 2021
@sindresorhus
Copy link
Owner

The error says it all.

@sindresorhus
Copy link
Owner

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

@LjjStar
Copy link
Author

LjjStar commented Sep 7, 2021

Hi, @sindresorhus
Actually, I use import {osLocale} from 'os-locale'; to import the package, but I still got this error message.
That's why I post this ticket.
I tried all the recommended method, but it will cause other error.

@sindresorhus
Copy link
Owner

sindresorhus commented Sep 7, 2021

This is not really the place to ask for ESM support. This package correctly implements ESM. Please ensure your project is fully ESM (just using import statements does not mean it's native ESM). The above link has a guide on how to make your project ESM.

@LjjStar
Copy link
Author

LjjStar commented Sep 7, 2021

Thank you for your reply. @sindresorhus
I will try it in my project.

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