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

import as ES module give me an undefined object #67

Closed
mbsanchez01 opened this issue Aug 8, 2023 · 5 comments
Closed

import as ES module give me an undefined object #67

mbsanchez01 opened this issue Aug 8, 2023 · 5 comments

Comments

@mbsanchez01
Copy link

When I import this module using the next code

import ISO6391 from 'iso-639-1';
console.log(ISO6391.getAllCodes());

I've got the error "Cannot read properties of undefined (reading 'getAllCodes')" however, if I import it using require all works fine, but, it is not normal to have code like this, it is not harmonics.

import { Injectable } from '@nestjs/common';
import { CreateLanguageDto } from './dto/create-language.dto';
import { UpdateLanguageDto } from './dto/update-language.dto';
const ISO6391 = require('iso-639-1'); //import is not working

Could you fix this please ?

@meikidd
Copy link
Owner

meikidd commented Aug 18, 2023

@mbsanchez01
Thank you for your feedback, I released a new version v3.0.0 for this. Please help to check.

@meikidd meikidd closed this as completed Aug 18, 2023
@mbsanchez01
Copy link
Author

I don't know why it is happening to me, I'm in a NestJs project, and to make it work I need to work around it:

import * as ISO6391 from 'iso-639-1';

console.log((ISO6391 as any).getAllCodes());

I'm using version 3.0.1

@meikidd
Copy link
Owner

meikidd commented Sep 2, 2023

@mbsanchez01
Could you provide a minimal reproducible repo? So that I can try replicate it on my side.

@mbsanchez01
Copy link
Author

Please check this repository out: https://github.com/mbsanchez01/iso639bug

@meikidd
Copy link
Owner

meikidd commented Sep 2, 2023

@mbsanchez01 You can try adding "esModuleInterop": true to your tsconfig.json file, it should fix the issue.

https://www.typescriptlang.org/tsconfig#esModuleInterop

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