Docs examples don't work with Typescript in ESM project
See original GitHub issueI 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:
- Created a year ago
- Comments:7 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Oh I see. Your project is ESM so
import Redis from 'ioredis'
will makeRedis
a namespace. You have to useimport { 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
Thanks for the quick fix, this helped me.