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

TypeError: Semaphore is not a constructor #8

Open
adam-nielsen opened this issue Aug 21, 2022 · 3 comments
Open

TypeError: Semaphore is not a constructor #8

adam-nielsen opened this issue Aug 21, 2022 · 3 comments

Comments

@adam-nielsen
Copy link

Is there a trick to using this module in a Typescript project?

import Semaphore from 'semaphore-async-await';
const lock = new Semaphore(1);

TypeError: Semaphore is not a constructor

I was able to work around the issue by changing the import statement to this, but it seems a bit dodgy:

import SemaphoreModule from 'semaphore-async-await';
// Not sure why we need to do it this way...
const Semaphore = (SemaphoreModule as any)['default'];

const lock = new Semaphore(1); // works now

Am I doing something wrong?

@gombosg
Copy link

gombosg commented Aug 21, 2022

Can you attach some playground or zipped example?

@adam-nielsen
Copy link
Author

Here's an example: example.zip

Run it via:

npm install
npx ts-node index.ts

It looks like the issue is around module handling. If my code isn't a module then it seems to work, but once I configure it to work as a module that's when it seems to dislike the Semaphore constructor.

@ffMathy
Copy link

ffMathy commented Nov 24, 2022

I'm getting the same error.

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

3 participants