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

Issue with importing specific languages in TypeScript #107

Closed
Sergiobop opened this issue May 31, 2023 · 7 comments
Closed

Issue with importing specific languages in TypeScript #107

Sergiobop opened this issue May 31, 2023 · 7 comments
Assignees

Comments

@Sergiobop
Copy link

Sergiobop commented May 31, 2023

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
Copy link
Collaborator

TylerVigario commented May 31, 2023

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 TylerVigario self-assigned this May 31, 2023
@TylerVigario TylerVigario linked a pull request May 31, 2023 that will close this issue
@TylerVigario TylerVigario removed a link to a pull request May 31, 2023
@TylerVigario
Copy link
Collaborator

TylerVigario commented May 31, 2023

@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
Copy link
Author

@TylerVigario Great, thank you for your fast response

Awesome package btw!

@TylerVigario
Copy link
Collaborator

@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 TylerVigario changed the title Can't import specific languages Issue with importing specific languages in TypeScript May 31, 2023
@TylerVigario
Copy link
Collaborator

@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
Copy link
Author

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
Copy link
Collaborator

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

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