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

typescript tsc build failed with error about module "strict-event-emitter" has no exported member 'StrictEventEmitter'. #1699

Closed
4 tasks done
neekey opened this issue Aug 15, 2023 · 1 comment
Labels
bug Something isn't working needs:triage Issues that have not been investigated yet. scope:node Related to MSW running in Node

Comments

@neekey
Copy link

neekey commented Aug 15, 2023

Prerequisites

Environment check

  • I'm using the latest msw version
  • I'm using Node.js version 14 or higher

Node.js version

v16.15.0

Reproduction repository

https://codesandbox.io/p/sandbox/confident-hugle-fz9j6l

Reproduction steps

The current setup is super simple:

  • it has msw@1.2.3 installed
  • it has typescript@4.5.4 installed

it has a dummy index.ts file which imported msw:

import { rest } from "msw";
import { setupServer } from "msw/node";

setupServer(
  // Handles a POST /login request
  rest.post("/hello_world", (req, res, ctx) => {
    return res(
      ctx.status(200),
      ctx.json({
        success: true,
      })
    );
  })
);

To reproduce the issue:

open the sandbox repo, simply in the terminal run: npm run build
you will see error while tsc trying to build the src/index.ts.

Current behavior

Got error:


node_modules/@mswjs/interceptors/lib/BatchInterceptor.d.ts:1:10 - error TS2724: '"strict-event-emitter"' has no exported member named 'EventMapType'. Did you mean 'EventMap'?

1 import { EventMapType } from 'strict-event-emitter';
           ~~~~~~~~~~~~

node_modules/@mswjs/interceptors/lib/utils/AsyncEventEmitter.d.ts:1:10 - error TS2305: Module '"strict-event-emitter"' has no exported member 'StrictEventEmitter'.

1 import { StrictEventEmitter, EventMapType } from 'strict-event-emitter';
           ~~~~~~~~~~~~~~~~~~

node_modules/@mswjs/interceptors/lib/utils/AsyncEventEmitter.d.ts:1:30 - error TS2724: '"strict-event-emitter"' has no exported member named 'EventMapType'. Did you mean 'EventMap'?

1 import { StrictEventEmitter, EventMapType } from 'strict-event-emitter';
                               ~~~~~~~~~~~~


Found 3 errors in 2 files.

Expected behavior

The build should finish without error

@neekey neekey added bug Something isn't working needs:triage Issues that have not been investigated yet. scope:node Related to MSW running in Node labels Aug 15, 2023
@kettanaito
Copy link
Member

Hi, @neekey. Thanks for reporting this.

This issue is caused by the different versions of strict-event-emitter that get installed:

└─┬ msw@1.2.3
  ├─┬ @mswjs/interceptors@0.17.9
  │ └── strict-event-emitter@0.2.8
  └── strict-event-emitter@0.4.6

I've started the effort to publish a backport to @mswjs/interceptors that'd bump that dependency to 0.4 in mswjs/interceptors#382 but encountered some type conflicts and didn't move further with that.

How to solve this?

To resolve this, disable type-checking of third-party libraries by setting "skipLibCheck": true in yout tsconfig.json. You shouldn't be validating third-party types anyway, and it's a good default to have that option enabled in your projects.

I will close this issue because it's not something we can address on MSW's side.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs:triage Issues that have not been investigated yet. scope:node Related to MSW running in Node
Projects
None yet
Development

No branches or pull requests

2 participants