enzymejs / enzyme

JavaScript Testing utilities for React
https://enzymejs.github.io/enzyme/
MIT License
19.95k stars 2.01k forks source link

Cannot find module with enzyme #2467

Closed wjonesusna2012 closed 9 months ago

wjonesusna2012 commented 3 years ago

Current behavior

After running yarn test I get the following error:

Test suite failed to run

Cannot find module 'react-dom' from 'ReactSixteenAdapter.js'

However, Jest was able to find:
    './ReactSixteenAdapter.js'
    './ReactSixteenAdapter.js.map'

You might want to include a file extension in your import, or update your 'moduleFileExtensions', which is currently ['web.js', 'js', 'web.ts', 'ts', 'web.tsx', 'tsx', 'json', 'web.jsx', 'jsx', 'node'].

See https://jestjs.io/docs/en/configuration#modulefileextensions-array-string

  at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:259:17)
  at Object.<anonymous> (../node_modules/enzyme-adapter-react-16/src/ReactSixteenAdapter.js:3:1)

Expected behavior

Your environment

React app was created using yarn create-app react-app demo dependencies were installed with yarn add

package.json is below:

{
  "name": "demo",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^5.11.4",
    "@testing-library/react": "^11.1.0",
    "@testing-library/user-event": "^12.1.10",
    "react": "16.9.0",
    "react-dom": "16.9.0",
    "react-scripts": "3.1.1",
    "react-test-renderer": "16.9.0",
    "web-vitals": "^0.2.4"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

App.test.js is below:

import App from './App';
import Enzyme from 'enzyme';
import EnzymeAdapter from 'enzyme-adapter-react-16';
import React from 'react';

Enzyme.configure({adapter: new EnzymeAdapter()});
test('renders learn react link', () => {
  render(<App />);
  const linkElement = screen.getByText(/learn react/i);
  expect(linkElement).toBeInTheDocument();
});

API

Version

library version
enzyme 16
react 16.9.0
react-dom 16.9.0
react-test-renderer 16.9.0
adapter (below)

Adapter

wjonesusna2012 commented 3 years ago

I have removed node-modules and re-installed with yarn multiple times with the same effect.

ljharb commented 3 years ago

This is a jest issue, not an enzyme one, since enzyme doesn't "find" any modules. Additionally, your package.json doesn't contain enzyme at all, it contains react-testing-library packages, so I'm a bit confused.

akinnee commented 9 months ago

I had this start happening after upgrading from enzyme 2.9.1 to 3.11.0.

ljharb commented 9 months ago

@akinnee Please file a new issue with a complete issue template.

I'm going to close this one due to lack of response from the OP.