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 'react' from 'ReactSixteenAdapter.js' #1954

Closed
1 task done
Luchanso opened this issue Dec 24, 2018 · 8 comments
Closed
1 task done

Cannot find module 'react' from 'ReactSixteenAdapter.js' #1954

Luchanso opened this issue Dec 24, 2018 · 8 comments

Comments

@Luchanso
Copy link

Hi, I have some issue in my project about react high order component. I think it's because react moved in peerDependencies.

Cannot find module 'react' from 'ReactSixteenAdapter.js'
      at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:221:17)
      at Object.<anonymous> (node_modules/enzyme-adapter-react-16/build/ReactSixteenAdapter.js:15:14)

More logs:
https://travis-ci.com/Luchanso/react-has-mounted/builds/95682075#L456-L462
Pull Request with changes.

Version

library version
enzyme ^3.8.0
react ^16.7.0
react-dom ^16.7.0
react-test-renderer -
adapter (below) ^1.7.1

Adapter

  • enzyme-adapter-react-16
@ljharb
Copy link
Member

ljharb commented Dec 24, 2018

It being a peer dependency means you have to explicitly have it as a dep or dev dep on the top level. Have you?

Note that everything that’s not the top level app should have it as a peer dep (and dev dep) and not as a regular dep.

@Luchanso
Copy link
Author

I have component as a package and I want to test it, can you suggest best way how to be?

@ljharb
Copy link
Member

ljharb commented Dec 25, 2018

In that case, your package must have react as both a peer dep and a dev dep - the dev dep for testing, the peer dep to communicate compatibility to consumers.

@Luchanso
Copy link
Author

@ljharb okey, it's work, thank you for help 👍

@marcuszierke
Copy link

marcuszierke commented May 10, 2019

Hi @ljharb ,

I ran into the same issue with react-native. My test environment includes jest, enzyme, I also implemented typescript.

I have it in my dep an devdep

    "@types/react-test-renderer": "^16.8.1",
    "react": "16.3.1",
    "react-native": "0.55.4",
    "react-native-iap": "^2.4.0-beta5",
    "react-native-video": "^3.2.0"
  },
  "devDependencies": {
    "@types/enzyme": "^3.9.1",
    "@types/enzyme-adapter-react-16": "^1.0.5",
    "@types/he": "1.1.0",
    "@types/jest": "^24.0.12",
    "@types/react": "^16.8.17",
    "@types/react-native": "^0.57.53",
   .....
}

but I still go the error:

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

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

Any idea why?

@ljharb
Copy link
Member

ljharb commented May 10, 2019

enzyme-adapter-react-16 is explicitly meant to work with react-dom, so you must have that installed.

To use RN, you'd need an actual RN adapter - see #1436 for that.

@stuthib

This comment has been minimized.

@ljharb

This comment has been minimized.

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