Add support for typescript
Closed this issue · 4 comments
I tried using it in typescript project and it keeps throwing error
Could not find a declaration file for module 'google-currency-scraper'. '/home/zaeem/Downloads/Practice/Javascript/node_modules/google-currency-scraper/index.js' implicitly has an 'any' type.
Trynpm i --save-dev @types/google-currency-scraper
if it exists or add a new declaration (.d.ts) file containingdeclare module 'google-currency-scraper';
I tried installing @types/google-currency-scraper
but it doesn't exist in the registry. Can typescript support be added?
Hi.
We talked about this yesterday. 😄 (#13)
I've just added type declarations. It should be fine now. Could you please upgrade to 3.2.0 and let me know if it helps? I would like to mark this issue as resolved and close it.
Yes, thank you for adding the typescript support. But I've ran into another issue, there seems to be problem with running the code when I try with ts-node or using it inside NestJS server, server doesn't start.
Error [ERR_REQUIRE_ESM]: require() of ES Module /home/zaeem/Downloads/Projects/Barter/BARTER-BE-DEV/node_modules/google-currency-scraper/index.js from /home/zaeem/Downloads/Projects/Barter/BARTER-BE-DEV/dist/modules/currency-exchange/currency-exchange.service.js not supported.
Instead change the require of index.js in /home/zaeem/Downloads/Projects/Barter/BARTER-BE-DEV/dist/modules/currency-exchange/currency-exchange.service.js to a dynamic import() which is available in all CommonJS modules.
at TracingChannel.traceSync (node:diagnostics_channel:315:14)
at Object. (/home/zaeem/Downloads/Projects/Barter/BARTER-BE-DEV/dist/modules/currency-exchange/currency-exchange.service.js:14:35)
Error looks something like this, although when I tried running the ts file with bun it worked. but doesn't work ts-node.
Yes, thank you for adding the typescript support. But I've ran into another issue, there seems to be problem with running the code when I try with ts-node or using it inside NestJS server, server doesn't start.
Error [ERR_REQUIRE_ESM]: require() of ES Module /home/zaeem/Downloads/Projects/Barter/BARTER-BE-DEV/node_modules/google-currency-scraper/index.js from /home/zaeem/Downloads/Projects/Barter/BARTER-BE-DEV/dist/modules/currency-exchange/currency-exchange.service.js not supported.
Instead change the require of index.js in /home/zaeem/Downloads/Projects/Barter/BARTER-BE-DEV/dist/modules/currency-exchange/currency-exchange.service.js to a dynamic import() which is available in all CommonJS modules.
at TracingChannel.traceSync (node:diagnostics_channel:315:14)
at Object. (/home/zaeem/Downloads/Projects/Barter/BARTER-BE-DEV/dist/modules/currency-exchange/currency-exchange.service.js:14:35)Error looks something like this, although when I tried running the ts file with bun it worked. but doesn't work ts-node.
google-currency-scraper
is an ES Module and cannot be imported using require()
in a CommonJS module. Instead, you need to use the dynamic import()
syntax available in CommonJS.
(async () => {
const googleCurrencyScraper = await import("google-currency-scraper);
})();
You can read more about it here: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
Alright, thanks.