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

Cannot find module '@pacote/jest-either' from 'test/.../...' when upgrade to 5.0.0 #333

Open
recklyss opened this issue Nov 4, 2021 · 1 comment
Labels
bug Something isn't working

Comments

@recklyss
Copy link

recklyss commented Nov 4, 2021

What

When I upgrade @pacote/jest-either from 4.0.9 to 5.0.0, got error when running test:

Test suite failed to run

    Cannot find module '@pacote/jest-either' from ...

ENV

  • Node 14
  • "ts-jest": "27.0.5"
  • "jest": "27.1.0"

Code

import matchers from '@pacote/jest-either';
expect.extend(matchers);

...

expect(something).toBeLeft();

I tried some solutions searched from StackOverflow, didn't solve the problem, can anyone help with it?

Tried: modify modulePaths or moduleDirectories, didn't work...

@goblindegook goblindegook added the bug Something isn't working label Dec 18, 2021
@goblindegook
Copy link
Member

There seems to be an issue with the package, but for ESM support in Jest this is what I've been able to piece together:

  • npm install --save-dev jest@next ts-jest@next
  • Follow setup instructions for ts-jest with ESM support
  • Setup test script to run with NODE_OPTIONS=--experimental-vm-modules
  • Import @pacote/jest-either/lib instead of just @pacote/jest-either (this is the part that needs to be fixed)

Sample project

package.json

{
  "scripts": {
    "test": "NODE_OPTIONS=--experimental-vm-modules jest"
  },
  "jest":  {
    "preset": "ts-jest/presets/default-esm",
    "globals": {
      "ts-jest": {
        "useESM": true
      }
    },
    "moduleNameMapper": {
      "^(\\.{1,2}/.*)\\.js$": "$1"
    }
  },
  "devDependencies": {
    "@pacote/jest-either": "^5.0.0",
    "fp-ts": "^2.11.5",
    "jest": "^27.0.0-next.11",
    "ts-jest": "^27.0.0-next.12",
    "typescript": "^4.5.4"
  }
}

test.ts

import { right } from 'fp-ts/Either'
import matchers from '@pacote/jest-either/lib'

expect.extend(matchers)

test("sanity", () => {
  expect(right('ok')).toEqualRight('ok')
})

tsconfig.json

{
  "compilerOptions": {
    "moduleResolution": "node"
  }
}

Hope this helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants