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

Don't work with require #311

Open
modox94 opened this issue Jun 29, 2023 · 5 comments
Open

Don't work with require #311

modox94 opened this issue Jun 29, 2023 · 5 comments

Comments

@modox94
Copy link

modox94 commented Jun 29, 2023

Can'r import this package with require. Everything ok with modern import.

/home/nike/Desktop/anime-advisor/node_modules/@chez14/mal-api-lite/build/index.cjs:4
var got = require('got');
          ^

Error [ERR_REQUIRE_ESM]: require() of ES Module /home/nike/Desktop/anime-advisor/node_modules/got/dist/source/index.js from /home/nike/Desktop/anime-advisor/node_modules/@chez14/mal-api-lite/build/index.cjs not supported.
Instead change the require of index.js in /home/nike/Desktop/anime-advisor/node_modules/@chez14/mal-api-lite/build/index.cjs to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (/home/nike/Desktop/anime-advisor/node_modules/@chez14/mal-api-lite/build/index.cjs:4:11)
    at Object.<anonymous> (/home/nike/Desktop/anime-advisor/app.js:79:23) {
  code: 'ERR_REQUIRE_ESM'
}
@chez14
Copy link
Owner

chez14 commented Jul 1, 2023

Hi @modox94,

Can you please tell me your dev environment? Node version, are you using ESM, and MAL Api SDK version?

Thank you!

@modox94
Copy link
Author

modox94 commented Jul 1, 2023

Hi. I attached package files to message. I use CJM at this repo. I tried to use your package with ESM and it works fine, but I need CJM support.
node v16.20.0
npm v9.7.2
package.json.txt
package-lock.json.txt

@chez14
Copy link
Owner

chez14 commented Jul 1, 2023

Noted, I'll try to find a way on how to make this work with CJS. Thank you for reporting!

@chez14
Copy link
Owner

chez14 commented Jul 3, 2023

Hi @modox94,

Thank you for waiting, I have consulted with some of my friends that have better understanding with ESM and I have read some blogs about it too. Apparently it's not possible to use newer Got with CJS.

This project uses newer Got, so I need to update it to ESM too. You can actually use dynamic import to replace the require, but apparently i will need top-level await as well. Unfortunately to use top-level await, your package must be converted to ESM ("type": "module" in package.json) as well.


That being said, since I do not use their deeper APIs, I kind of want to try to support older Got version (v11) that still support CJS as well. Hopefully it can still work with this library.

But In the future, I'll drop support for CJS because older got is no longer actively supported. I made mistake when bumping up the major version by not removing the CJS build i copied from my older library project. I'm sorry :(.

I'll update you with my findings. Thank you!

@chez14
Copy link
Owner

chez14 commented Jul 15, 2023

Hi @modox94,

I've published new version so that you can use got with older version. The tests seems okay, but I have not tested it much further.

To install this new version with older version of got, you can run following commands:

yarn add @chez14/mal-api-lite@^1.2.7 got@^11.8

## or NPM
npm i -s @chez14/mal-api-lite@^1.2.7 got@^11.8 && npm dedupe

Thank you!

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