TypeError: redlock_1.default is not a constructor

See original GitHub issue

ts code:

import Client from 'ioredis';
import Redlock from 'redlock';

const redisA = new Client({ host: 'ubuntu' });

const redlock = new Redlock(
  // You should have one client for each independent redis node
  // or cluster.
  [redisA],
  {
    driftFactor: 0.01, // multiplied by lock ttl to determine drift time
    retryCount: 10,
    retryDelay: 200, // time in ms
    retryJitter: 200, // time in ms
  },
);

error: const redlock = new Redlock( ^ TypeError: redlock_1.default is not a constructor at Object.<anonymous> (c:\Users\GO_DIE\Desktop\nest-study\test\1.ts:6:17) at Module._compile (internal/modules/cjs/loader.js:1200:30) at Module.m._compile (C:\Users\GO_DIE\AppData\Roaming\nvm\v14.4.0\node_modules\ts-node\src\index.ts:1056:23) at Module._extensions…js (internal/modules/cjs/loader.js:1220:10) at Object.require.extensions.<computed> [as .ts] (C:\Users\GO_DIE\AppData\Roaming\nvm\v14.4.0\node_modules\ts-node\src\index.ts:1059:12) at Module.load (internal/modules/cjs/loader.js:1049:32) at Function.Module._load (internal/modules/cjs/loader.js:937:14) at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12) at main (C:\Users\GO_DIE\AppData\Roaming\nvm\v14.4.0\node_modules\ts-node\src\bin.ts:198:14) at Object.<anonymous> (C:\Users\GO_DIE\AppData\Roaming\nvm\v14.4.0\node_modules\ts-node\src\bin.ts:288:3)
at Module._compile (internal/modules/cjs/loader.js:1200:30) at Object.Module._extensions…js (internal/modules/cjs/loader.js:1220:10) at Module.load (internal/modules/cjs/loader.js:1049:32) at Function.Module._load (internal/modules/cjs/loader.js:937:14) at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12) at internal/main/run_main_module.js:17:47

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
mike-marcaccicommented, Dec 14, 2021

Hy @YuriyTigiev,

I think your issue is a simple one 😄

Per the Use in CommonJS Projects section of the README:

Beginning in version 5, this package is published primarily as an ECMAScript module. While this is universally accepted as the format of the future, there remain some interoperability quirks when used in CommonJS node applications. For major version 5, this package also distributes a copy transpiled to CommonJS. Please ensure that your project either uses either the ECMAScript or CommonJS version but NOT both.

The Redlock class is published as the “default” export, and can be imported with:

const { default: Redlock } = require("redlock");

In version 6, this package will stop distributing the CommonJS version.

Updating to your import statement to the above should fix your issue!

2reactions
mike-marcaccicommented, Nov 26, 2021

I just published v5.0.0-beta.1 which now publishes both ESM and CJS versions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error: *.default is not a constructor - Stack Overflow
I get the following error, when testing some javascript code, transpiled from a typescript file. Here is the error: Error: _mapAction2.default ...
Read more >
TypeError: web3_1.default is not a constructor
I'm trying to convert a DApp that uses web3.js from JavaScript to TypeScript, but I have encountered a bunch of runtime errors. I'm...
Read more >
Hi, to fix this `o.default is not a constructor`, you need to adjust ...
to:. “Hi, to fix this `o.default is not a constructor`, you need to adjust your import statement, from:” is published by Éverton Roberto...
Read more >
TypeError: _gauge2.default is not a constructor - Laracasts
I'm trying to wrap this gauge http://bernii.github.io/gauge.js/ in a Vue component, but Vue gives me the error: TypeError: _gauge2.default is not a ......
Read more >
Mock ES6 class | ts-jest - GitHub Pages
TypeError : sound_player_1.default is not a constructor. because soundPlayer.default does not point to a function. Your mock has to return an ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found