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

Default Import Error with ioredis Prevents TypeScript Compilation with esModuleInterop Disabled #129

Closed
bobdercole opened this issue Feb 7, 2020 · 4 comments · Fixed by #132
Labels

Comments

@bobdercole
Copy link
Contributor

Hello,

My TypeScript projects fails to compile due to an error in some BullMQ files. Here is the error:

$ tsc -p .
node_modules/bullmq/dist/classes/redis-connection.d.ts:3:8 - error TS1259: Module '"/application/node_modules/@types/ioredis/index"' can only be default-imported using the 'esModuleInterop' flag

3 import IORedis, { Redis } from 'ioredis';
         ~~~~~~~

  node_modules/@types/ioredis/index.d.ts:43:1
    43 export = IORedis;
       ~~~~~~~~~~~~~~~~~
    This module is declared with using 'export =', and can only be used with a default import when using the 'esModuleInterop' flag.

I found this problem in the following files:

import IORedis, { Redis } from 'ioredis';

import IORedis from 'ioredis';

import IORedis from 'ioredis';

import IORedis from 'ioredis';

import IORedis from 'ioredis';

import IORedis from 'ioredis';

I do have esModuleInterop disabled. The issues seems to go away if I enabled esModuleInterop. However, I don't think that this flag should be required.

I can confirm that the error goes away if the ioredis imports within BullMQ are changed to the recommended ioredis usage:

import * as Redis from "ioredis";
https://github.com/DefinitelyTyped/DefinitelyTyped/blob/946a98e60e6ae4f4f2910f1c75b8403e0f676876/types/ioredis/index.d.ts#L21

Any thoughts? Thanks!

@manast
Copy link
Contributor

manast commented Feb 8, 2020

That error goes away but don't you get other errors instead? I don't think IORedis typings are fully following the modern TS standard for exporting classes so I am not sure what can be done other than enabling the esModuleInterop flag...

@bobdercole
Copy link
Contributor Author

I created a PR as a proof of concept. Yes, I did encounter some other errors when I disabled esModuleInterop in BullMQ. I addressed those in the PR as well.

It seems people have had this issue before with ioredis (redis/ioredis#712) and TypeScript in general (microsoft/TypeScript#28009).

I am not sure if my change is conventional. It does fix my problem though. Do you have any thoughts?

@robcresswell
Copy link

@bobdercole I have the same issue here, and your patch is correct, aside from the comments from @manast about using the type only, when appropriate. import * as IORedis is the way to go.

@manast
Copy link
Contributor

manast commented Mar 2, 2020

🎉 This issue has been resolved in version 1.8.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants