question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot find module '../node_modules/.vite/@testing-library_react.js' from 'src/__tests__/unit/App.test.tsx'

See original GitHub issue

I am running a very basic test copied from the React + Typescript example.

import React from "react";

import { render, screen } from "@testing-library/react";
import App from "../../App";

test("renders learn react link", () => {
  render(<App />);
  const linkElement = screen.getByText(/learn react/i);
  expect(linkElement).toBeInTheDocument();
});

Sadly, it throws me an error

Test suite failed to run

    Cannot find module '.../node_modules/.vite/@testing-library_react.js' from 'src/__tests__/unit/App.test.tsx'

      at Resolver.resolveModule (node_modules/jest-resolve/build/resolver.js:318:11)

I checked my .vite folder, I do have testing library react js installed

image

This is my package.json image

I have tried placing it under dependencies and also devDependencies, but nothing seems to work.

Any ideas?

My full package.json. I really want to use vite-jest ! But if this doesn’t work, I would have to go back to my hackish babel method of running jest with vite.

"scripts": {
    "dev": "vite --host",
    "build": "./build.sh",
    "serve": "vite preview",
    "lint": "eslint src",
    "test:unit": "vite-jest"
  },
  "dependencies": {
    "@testing-library/jest-dom": "^5.14.1",
    "@testing-library/react": "^12.0.0",
    "react": "^17.0.0",
    "react-dom": "^17.0.0"
  },
  "devDependencies": {
    "@types/jest": "^27.0.1",
    "@types/node": "^16.9.0",
    "@types/react": "^17.0.0",
    "@types/react-dom": "^17.0.0",
    "@typescript-eslint/eslint-plugin": "^4.31.0",
    "@vitejs/plugin-react-refresh": "^1.3.1",
    "autoprefixer": "^10.3.4",
    "eslint": "^7.32.0",
    "eslint-config-prettier": "^8.3.0",
    "eslint-plugin-prettier": "^4.0.0",
    "eslint-plugin-react": "^7.25.1",
    "jest": "^27.1.1",
    "jest-environment-jsdom": "^27.1.1",
    "postcss": "^8.3.6",
    "tailwindcss": "^2.2.13",
    "typescript": "^4.3.2",
    "vite": "^2.5.4",
    "vite-jest": "^0.0.3"
  }

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:3
  • Comments:7

github_iconTop GitHub Comments

1reaction
leeyh20commented, Sep 11, 2021

It is not a Windows issue, I’m running this on Linux, Ubuntu 18.04.

0reactions
ranger-rosscommented, Jun 4, 2022

im having the same issue, was there ever a resolution to this issue?

Read more comments on GitHub >

github_iconTop Results From Across the Web

jest: Cannot find module 'react', and other node_modules
I have a __tests__ directory in my root folder. One of my test files, called Component.js , starts with some simple imports: import...
Read more >
testing-library/react-native - npm
Simple and complete React Native testing utilities that encourage good testing practices.. Latest version: 11.5.0, last published: a month ...
Read more >
How to Test React Components in TypeScript | Pluralsight
In this guide, you'll learn how to get started quickly writing tests using TypeScript, React, and Jest in an idiomatic way. There are...
Read more >
Setup Jest with Vite (featuring SWC) - Blog by hung.dev
By default "node_modules" folder is ignored by transformers. ... Details: /jest-vite/src/__tests__/App.test.tsx:1 ({"Object.
Read more >
Setup - Testing Library
The example below sets up data providers using the wrapper option to render . Javascript; Typescript. my-component.test.jsx. - import { render ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found