sindresorhus / ora

Elegant terminal spinner
MIT License
9.08k stars 269 forks source link

Can't be use with ES Modules #239

Closed gihanrangana closed 2 months ago

gihanrangana commented 2 months ago

getting an error when I try to run the ora on my ts project

Error [ERR_REQUIRE_ESM]: require() of ES Module C:\Projects\apix-js\@apixjs\api\node_modules\.pnpm\ora@8.0.1\node_modules\ora\index.js from C:\Projects\apix-js\@apixjs\api\lib\plugins\ora.ts not supported.
Instead change the require of index.js in C:\Projects\apix-js\@apixjs\api\lib\plugins\ora.ts to a dynamic import() which is available in all CommonJS modules.
    at require.extensions.<computed> [as .js] (C:\Projects\apix-js\@apixjs\api\node_modules\.pnpm\ts-node@10.9.2_@types+node@20.14.2_typescript@5.4.5\node_modules\ts-node\dist\index.js:851:20)
    at C:\Projects\apix-js\@apixjs\api\lib\plugins\ora.ts:35:65
    at async initPlugin (C:\Projects\apix-js\@apixjs\api\lib\plugins\ora.ts:35:17) {
  code: 'ERR_REQUIRE_ESM'
}
sindresorhus commented 2 months ago

Your project needs to be proper ESM: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c

damusix commented 2 months ago

Great package, but the fact that the maintainers have to be soooo edgy they refuse to support CJS is a huge bummer.

I'm using Node 22 with experimental ESM requires and it's still a PITA to get this running. What a shame. Wish y'all had a different mindset. It's really not that hard to add SWC and transpile into CJS.