forzagreen / n2words

Convert numerical numbers to written numbers, in 25+ languages.
MIT License
87 stars 22 forks source link

Issue with importing specific languages in TypeScript #107

Closed Sergiobop closed 1 year ago

Sergiobop commented 1 year ago

After upgrading to 1.16.1 i can't import specific languages:

From the wiki: import n2wordsES from 'n2words/i18n/ES.js'

Cannot find module 'n2words/i18n/ES.js' or its corresponding type declarations.

import n2wordsES from 'n2words/i18n/ES.js';

If i change the import to import n2wordsES from 'n2words/lib/i18n/ES.js';

Error: Module not found: Error: Package path ./lib/i18n/ES.js is not exported from package node_modules/n2words (see exports field in node_modules/n2words/package.json)

Downgrading to 1.15 since it works as spected: import n2wordsES from 'n2words/lib/i18n/ES.mjs' -> Works in 1.15

TylerVigario commented 1 year ago

Thank you for reporting this! This is most likely caused by something in #105.

I'm not 100% familiar with TypeScript but I think there are some type file requirements which could be an issue here as well. I'm just not sure why it worked before from source but not anymore. I'll throw the new version in a blank TypeScript project after work and see what I find.

In the meantime I found this article which may be helpful - https://askjavascript.com/cannot-find-module-and-its-corresponding-type-declarations/

TylerVigario commented 1 year ago

@Sergiobop I could get around this TypeScript issue by preceding the import line with // @ts-ignore. See the example below and let me know if this works for you as well.

// @ts-ignore
import n2words from 'n2words/i18n/ES'

console.log(n2words)

I'll look into providing a proper type definition file for TypeScript users.

Sergiobop commented 1 year ago

@TylerVigario Great, thank you for your fast response

Awesome package btw!

TylerVigario commented 1 year ago

@Sergiobop We thank you for your kind words! Going to close this for now but will follow up if, and when, I add proper TypeScript definitions.

TylerVigario commented 1 year ago

@Sergiobop I've gone into further discussion in #109 and created a wiki for importing in TypeScript - https://github.com/forzagreen/n2words/wiki/Importing-in-TypeScript

Sergiobop commented 1 year ago

Thank you @TylerVigario , i endep up importing the library like this:

// @ts-ignore import n2wordsES from 'n2words/i18n/es.js';

And it's working

TylerVigario commented 1 year ago

@Sergiobop I've added typings in #112 which is included in v1.16.3. // @ts-ignore should no longer be needed. Cheers!