question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Docs examples don't work with Typescript in ESM project

See original GitHub issue

I actually had to do this to get started

import Redis from 'ioredis'
const redis = new Redis.default()

or

import { default as Redis } from 'ioredis'
const redis = new Redis()

using just new Redis() results in Typescript error:

This expression is not constructable.
  Type 'typeof import("node_modules/ioredis/built/index")' has no construct signatures.ts(2351)

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
luincommented, Aug 9, 2022

Oh I see. Your project is ESM so import Redis from 'ioredis' will make Redis a namespace. You have to use import { default as Redis } from "ioredis" as you mentioned. Will think about a fix or add a notice to README.

Related to https://github.com/luin/ioredis/issues/1624

0reactions
rvritacommented, Sep 19, 2022

Thanks for the quick fix, this helped me.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Documentation - ECMAScript Modules in Node.js - TypeScript
js has been working to support running ECMAScript modules (ESM). This has been a very difficult feature to support, since the foundation of...
Read more >
TypeScript and native ESM on Node.js - 2ality
In this blog post, I'll explain everything you need to know in order to use and produce native ECMAScript modules on Node.js.
Read more >
TypeScript cannot emit valid ES modules due to file extension ...
I have seen the work on Node12 module resolution, and it is fantastic, but it does not solve the problem of allowing maintainers...
Read more >
Avoid these issues when using new ECMAScript modules in ...
If you don't use typescript you might have to do some rewriting if you want to get your app updated. Here are solutions...
Read more >
Understanding TypeScript 4.7 and ECMAScript module support
The TypeScript 4.7 release comes a major upgrade to ECMAScript module support for Node.js, allowing developers to better support modules.
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