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

Vitest Error: Missing "./extend-expect" specifier in "@testing-library/jest-dom" package #539

Closed
bradleyball opened this issue Oct 9, 2023 · 5 comments

Comments

@bradleyball
Copy link

bradleyball commented Oct 9, 2023

I am trying to migrate from Jest to Vitest. I'm running into issues with the latest versions of required packages.

Package Versions:

"@testing-library/jest-dom": "^6.1.3",
"@testing-library/react": "^14.0.0",
"vitest": "^0.34.6",

What I tried in the setup file

import '@testing-library/jest-dom/vitest'

and also tried

import * as matchers from '@testing-library/jest-dom/matchers'
import { afterEach, beforeEach, expect, vi } from 'vitest'

declare module 'vitest' {
  interface Assertion<T = any>
    extends jest.Matchers<void, T>,
      matchers.TestingLibraryMatchers<T, void> {}
}

expect.extend(matchers)

What I tried in the setup file

vite.config file

  test: {
    globals: true,
    environment: 'jsdom',
    setupFiles: './src/vitestSetup.ts',
  },

Error stack:

Error: Missing "./extend-expect" specifier in "@testing-library/jest-dom" package
 ❯ e node_modules/vitest/node_modules/vite/dist/node/chunks/dep-2b82a1ce.js:21445:25
 ❯ n node_modules/vitest/node_modules/vite/dist/node/chunks/dep-2b82a1ce.js:21445:627
 ❯ o node_modules/vitest/node_modules/vite/dist/node/chunks/dep-2b82a1ce.js:21445:1297
 ❯ resolveExportsOrImports node_modules/vitest/node_modules/vite/dist/node/chunks/dep-2b82a1ce.js:28741:20
 ❯ resolveDeepImport node_modules/vitest/node_modules/vite/dist/node/chunks/dep-2b82a1ce.js:28760:31
 ❯ tryNodeResolve node_modules/vitest/node_modules/vite/dist/node/chunks/dep-2b82a1ce.js:28448:20
 ❯ Context.resolveId node_modules/vitest/node_modules/vite/dist/node/chunks/dep-2b82a1ce.js:28207:28
 ❯ Object.resolveId node_modules/vitest/node_modules/vite/dist/node/chunks/dep-2b82a1ce.js:44269:32
 ❯ TransformContext.resolve node_modules/vitest/node_modules/vite/dist/node/chunks/dep-2b82a1ce.js:43985:23
@bradleyball
Copy link
Author

Similar issue as here: #439 (comment)

@grainrigi
Copy link

grainrigi commented Oct 18, 2023

It's just saying Cannot import '@testing-library/jest-dom/extend-expect'.
For me, removing all import '@testing-library/jest-dom/extend-expect' solved the problem.

@bradleyball
Copy link
Author

@grainrigi Thanks! I had that import statement in my testing library untils. That fixed my problem.

@karthikatl
Copy link

i still have this issue

@Hri100v
Copy link

Hri100v commented Feb 20, 2025

The solution for me was to add a reference for the "vitest" in the "jest-dom" path:
import '@testing-library/jest-dom/vitest'

Like in the first suggestion! ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants