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

update strict-event-emitter to at least v0.3.x to avoid implicit dependency on Node.js type definitions. #1519

Closed
4 tasks done
chrisguttandin opened this issue Jan 14, 2023 · 13 comments · Fixed by #1522 or open-draft/strict-event-emitter#12
Labels
bug Something isn't working needs:triage Issues that have not been investigated yet. scope:browser Related to MSW running in a browser

Comments

@chrisguttandin
Copy link
Collaborator

Prerequisites

Environment check

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

Browsers

Firefox

Reproduction repository

https://github.com/chrisguttandin/msw-test

Reproduction steps

Run the following commands:

mkdir msw-test
cd msw-test 
npm init --yes
npm install msw
npm install typescript --save-dev
tsc --init --skipLibCheck false --target es2022 --types " "
touch index.ts

Open index.ts and add the following content:

// index.ts
import { setupWorker } from 'msw';

setupWorker;

Compile the project:

tsc -p tsconfig.json

Current behavior

node_modules/strict-event-emitter/lib/StrictEventEmitter.d.ts:1:30 - error TS7016: Could not find a declaration file for module 'events'. '.../msw-test/node_modules/events/events.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/events` if it exists or add a new declaration (.d.ts) file containing `declare module 'events';`

1 import { EventEmitter } from 'events';

Expected behavior

I would expect it to compile.

@chrisguttandin chrisguttandin added bug Something isn't working scope:browser Related to MSW running in a browser needs:triage Issues that have not been investigated yet. labels Jan 14, 2023
@chrisguttandin
Copy link
Collaborator Author

Hi @kettanaito I think the error would be resolved when updating strict-event-emitter. I guess @mswjs/interceptors would need to be updated, too. It seems to depend on strict-event-emitter as well.

I'm happy to give this a try if you agree.

@kettanaito
Copy link
Member

Hey, @chrisguttandin! Thanks for raising this.

If MSW depends on this package directly then let's bump it. You won't be able to update the Interceptors because the newest version already ships with the Fetch API support so its being updated as a part of the said feature in MSW.

People can use package resolutions for now to avoid this issue, I hope.

@kettanaito
Copy link
Member

I can use some help with the strict-event-emitter update for the Interceptors though mswjs/interceptors#324

@chrisguttandin
Copy link
Collaborator Author

I created a fresh fork of msw and ran yarn install. I got this error:

➤ YN0066: │ typescript@patch:typescript@npm%3A4.5.4#builtin<compat/typescript>::version=4.5.4&hash=8133ad: Cannot apply hunk #2 (set enableInlineHunks for details)
➤ YN0066: │ typescript@patch:typescript@npm%3A4.9.3#builtin<compat/typescript>::version=4.9.3&hash=8133ad: Cannot apply hunk #2 (set enableInlineHunks for details)

Does that somehow look familiar to you?

@kettanaito
Copy link
Member

@chrisguttandin, the first time I see that. Maybe check your Node version? I develop on 16.18.0.

@chrisguttandin
Copy link
Collaborator Author

I uninstalled yarn itself and re-installed it again. Now I'm on v1.22.19 of yarn. I'm also using Node.js v16. Everything works as expected now. I can run yarn install and yarn test.

I've created a PR to update over strict-event-emitter here: #1522.

kettanaito pushed a commit that referenced this issue Jan 17, 2023
* chore(deps): bump json5 from 0.2.6 to 0.4.3 (#1519)

* fix: replace StrictEventEmitter with Emitter
@kettanaito
Copy link
Member

Released: v0.49.3 🎉

This has been released in v0.49.3!

Make sure to always update to the latest version (npm i msw@latest) to get the newest features and bug fixes.


Predictable release automation by @ossjs/release.

@BoussonKarel
Copy link

BoussonKarel commented Jan 19, 2023

Hi, this latest bugfix release suddenly broke my Ember.js build.
Was not an issue in 0.49.2

image

@kettanaito @chrisguttandin

@kettanaito
Copy link
Member

Thanks for reporting this, @BoussonKarel. Looks like we need to compile strict-event-emitter to lower target to support older projects. Alternatively, migrate from the class private method syntax to private properties.

@kettanaito
Copy link
Member

Will be released as strict-event-emitter@3.4.4. Once that's out, re-install msw and you will get the latest dependency with the fix.

@BoussonKarel
Copy link

I looked into it further yesterday at it seemed like the issue is also ember-auto-import.

Class private methods are supposed to be enabled, but apparently they're not.

embroider-build/ember-auto-import#559

@BoussonKarel
Copy link

The strict-event-emitter update did fix it, thanks!

@IceDevelop74
Copy link

I'm facing the same issue with the 1.2.1 on an Angular Project.

browser.ts:

import { setupWorker } from 'msw'
import { handlers } from './handlers'

export const worker = setupWorker(...handlers);

I added src/mockServiceWorker.js in my angular.json and started the worker in my environment file.

Any idea what's going on ?

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:browser Related to MSW running in a browser
Projects
None yet
4 participants