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: AwaitLock is not a constructor #5

Closed
dvaruas opened this issue Sep 12, 2019 · 5 comments
Closed

TypeError: AwaitLock is not a constructor #5

dvaruas opened this issue Sep 12, 2019 · 5 comments

Comments

@dvaruas
Copy link

dvaruas commented Sep 12, 2019

With the new version 1.2.0 this piece of code throws the error
TypeError: AwaitLock is not a constructor

const AwaitLock = require('await-lock');
const lock = new AwaitLock();

This works with 1.1.3 version.

@ide
Copy link
Owner

ide commented Sep 12, 2019

Published a backwards compatibility fix in 1.2.1. I had to manually modify the build output so there is no commit that corresponds to this version of the package. Moving forward, this will not be supported in 2.0.0.

@ide ide closed this as completed Sep 12, 2019
@jsoldi
Copy link

jsoldi commented Aug 7, 2022

Having this problem to. Is it not possible to create an instance of AwaitLock? What's the alternative?

@ide
Copy link
Owner

ide commented Aug 7, 2022

The issue is with the way the module is loaded, not the constructor. Use ESM, either natively or with tsc, Babel, SWC, etc.

@Spenhouet
Copy link

I'm running into the same issue. Not sure what you mean. Everything else loads fine. Not this module. How to resolve this?

import AwaitLock from 'await-lock';

....

this.mutex = new AwaitLock();

this.mutex = new AwaitLock();
^
TypeError: AwaitLock is not a constructor
at new Model (file:///home/m/scripts/model.ts:78:16)
at file:///home/m/scripts/ecosystem.ts:109:14
at ModuleJob.run (node:internal/modules/esm/module_job:198:25)
at async Promise.all (index 0)
at async ESMLoader.import (node:internal/modules/esm/loader:385:24)
at async loadESM (node:internal/process/esm_loader:88:5)
at async handleMainPromise (node:internal/modules/run_main:61:12)

tsconfig.json:

"compilerOptions": {
    "module": "es2022",
    "moduleResolution": "node",
    "lib": ["es2020"],
    "target": "es2020",
    "esModuleInterop": true,

@Goostavo
Copy link

It's a export default module error. It can be fixed easily with adding .default

Working example:

const AwaitLock = require('await-lock').default;
let lock = new AwaitLock();

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

5 participants