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 "Must use import to load ES Module" in nestjs project #318

Open
chao-ryan opened this issue Mar 23, 2022 · 0 comments
Open

get error "Must use import to load ES Module" in nestjs project #318

chao-ryan opened this issue Mar 23, 2022 · 0 comments

Comments

@chao-ryan
Copy link

chao-ryan commented Mar 23, 2022

environment:
In nestjs project's package.json
"date-holidays": "3.14.4"
"@nestjs/core": "7.6.12",
...

holiday.service.ts
import Holidays from "date-holidays";

getHolidays() {
const holidays = new Holidays();
}

when i run project, i get error
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /media/ryan/home/work/sources/ryan-test-project/node_modules/astronomia/data/vsop87Bearth.js
require() of ES modules is not supported
require() of /media/media/ryan/home/work/sources/ryan-test-project/node_modules/astronomia/data/vsop87Bearth.js from /media/media/ryan/home/work/sources/ryan-test-project/node_modules/date-holidays-parser/lib/vsop87Bearth.cjs 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 vsop87Bearth.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /media/media/ryan/home/work/sources/ryan-test-project/node_modules/astronomia/package.json.
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1174:13)
......

Can I how to resolve the problem?

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

1 participant