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

AwaitLock is not a constructor when importing in Typescript #32

Open
kasbah opened this issue Aug 9, 2023 · 2 comments · May be fixed by #33
Open

AwaitLock is not a constructor when importing in Typescript #32

kasbah opened this issue Aug 9, 2023 · 2 comments · May be fixed by #33

Comments

@kasbah
Copy link

kasbah commented Aug 9, 2023

This is similar to #5 but I'm not using require but Typescript with moduleResolution: "node". https://github.com/kasbah/await-lock-bug-repro

git clone https://github.com/kasbah/await-lock-bug-repro && cd await-lock-bug-repro
yarn
yarn tsc
node example.js
TypeError: AwaitLock is not a constructor
    at file:///home/kaspar/projects/await-lock/repro/example.js:2:14
    at ModuleJob.run (node:internal/modules/esm/module_job:192:25)
    at async DefaultModuleLoader.import (node:internal/modules/esm/loader:228:24)
    at async loadESM (node:internal/process/esm_loader:40:7)
    at async handleMainPromise (node:internal/modules/run_main:66:12)
@kasbah
Copy link
Author

kasbah commented Aug 9, 2023

It may be related to https://stackoverflow.com/questions/63189533/how-can-i-solve-error-this-expression-is-not-constructable and the hint from TS docs:

Note that ES6 modules cannot directly export class objects.

@kasbah kasbah linked a pull request Aug 9, 2023 that will close this issue
@kasbah
Copy link
Author

kasbah commented Aug 10, 2023

A sort of workaround is to set target to ES5 in compiler options.

...
  "compilerOptions": {
    "noEmitOnError": false,
    "target": "ES5",
...

This does give a compilation error

node_modules/await-lock/build/AwaitLock.d.ts:5:5 - error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher.

5     #private;
      ~~~~~~~~

But the emitted code actually works.

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

Successfully merging a pull request may close this issue.

1 participant