PacoteJS / pacote

A box of goodies, in TypeScript.
https://pacotejs.github.io/pacote/
MIT License
18 stars 1 forks source link

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

Open recklyss opened 3 years ago

recklyss commented 3 years ago

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

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 commented 2 years ago

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:

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.