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

Compatibility issue with ESM in ws 8.x #11742

Closed
ai opened this issue Aug 11, 2021 · 2 comments
Closed

Compatibility issue with ESM in ws 8.x #11742

ai opened this issue Aug 11, 2021 · 2 comments

Comments

@ai
Copy link
Contributor

ai commented Aug 11, 2021

🐛 Bug Report

I am using Jest 27 ESM with ts-jest. In recent ws 8.x release, ws got ESM exports, but they do not work with Jest.

import { WebSocketServer } from 'ws'

works in pure Node.js, but leads to error in Jest:

    SyntaxError: The requested module 'ws' does not provide an export named 'WebSocketServer'

To Reproduce

Steps to reproduce the behavior:

Jest config:

{
    "preset": "ts-jest/presets/default-esm",
    "globals": {
      "ts-jest": {
        "useESM": true,
        "isolatedModules": true
      }
    },
    "testEnvironment": "node",
    "coverageThreshold": {
      "global": {
        "statements": 100
      }
    },
    "testPathIgnorePatterns": [
      "<rootDir>/node_modules/",
      "<rootDir>/test/servers"
    ],
    "coveragePathIgnorePatterns": [
      "<rootDir>/node_modules/",
      "<rootDir>/server/index.js"
    ]
  }

tsconfig.json:

{
  "compilerOptions": {
    "target": "es2018",
    "module": "esnext",
    "moduleResolution": "node",
    "esModuleInterop": true,
    "allowJs": true,
    "strict": true,
    "noEmit": true
  },
  "exclude": [
    "**/errors.ts"
  ]
}

index.js

import { WebSocketServer } from 'ws'

export default WebSocketServer

index.test.ts:

import cls from './index.js'

it('is a class', () => {
  expect(typeof cls).toEqual('function')
})

Expected behavior

Pass the test

envinfo

  System:
    OS: Linux 5.13 Fedora 34 (Workstation Edition) 34 (Workstation Edition)
    CPU: (8) x64 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz
  Binaries:
    Node: 16.6.2 - ~/.asdf/installs/nodejs/16.6.2/bin/node
    Yarn: 1.22.10 - ~/.asdf/shims/yarn
    npm: 7.20.3 - ~/.asdf/plugins/nodejs/shims/npm
  npmPackages:
    jest: ^27.0.6 => 27.0.6
@SimenB
Copy link
Member

SimenB commented Aug 12, 2021

@SimenB SimenB closed this as completed Aug 12, 2021
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants