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.

[React-Native] [Expo] Cannot find module 'react-dom' from 'styled-components.cjs.js'

See original GitHub issue

Environment

System:

  • OS: macOS 10.14
  • CPU: (4) x64 Intel® Core™ i7-5557U CPU @ 3.10GHz
  • Memory: 330.20 MB / 16.00 GB
  • Shell: 3.2.57 - /bin/bash

Binaries:

  • Node: 10.7.0 - ~/.nvm/versions/node/v10.7.0/bin/node
  • Yarn: 1.7.0 - /usr/local/bin/yarn
  • npm: 6.5.0 - ~/.nvm/versions/node/v10.7.0/bin/npm

npmPackages:

  • styled-components: ^4.1.3 => 4.1.3

Reproduction

I’m working on a project on React native with Expo. I have a component that use a View and name Container.

import React from 'react'
import {
    CameraRoll,
    Button,
    Dimensions,
    FlatList,
    TouchableHighlight,
} from 'react-native'
import styled from 'styled-components/native'

export const Container = styled.SafeAreaView`
    flex: 1;
    background-color: transparent;
`

I have a file to run test with react-test-renderer who look like this :

// __tests__/Library-test.js
import React from 'react';
import {Container} from '../Library';
import renderer from 'react-test-renderer';
import 'jest-styled-components';

test('renders correctly', () => {
  const tree = renderer.create(<Container />).toJSON();
  expect(tree).toMatchSnapshot();
});

Expected Behavior

I was expecting to have the test working perfectly.

Actual Behavior

 FAIL  components/__tests__/Library-test.js
  ● Test suite failed to run

    Cannot find module 'react-dom' from 'styled-components.cjs.js'

      at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:221:17)
      at Object.<anonymous> (node_modules/styled-components/dist/styled-components.cjs.js:16:32)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:5
  • Comments:5

github_iconTop GitHub Comments

2reactions
SirPhemmieycommented, Jan 19, 2019

Hey, have you found a solution?

1reaction
mulholocommented, Jun 30, 2019

Yep, add styled-components/native in your import, not styled-components

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot find module 'react-dom/client' from 'node_modules ...
I think it's because your @testing-library/react using the newer version, just test with version of 12.1.2.
Read more >
styled-components - npm
Start using styled-components in your project by running `npm i ... See the documentation about React Native for more information.
Read more >
Module not found: Can't resolve 'react-dom' error | bobbyhadz
To solve the error Module not found: Error: Can't resolve 'react-dom', make sure to install the `react-dom` package by opening your terminal in...
Read more >
Invalid Hook Call Warning - React
You might be using a version of react-dom (< 16.8.0) or react-native (< 0.59) that doesn't yet support Hooks. You can run npm...
Read more >
failed to construct transformer react native - You.com
Failed to construct transformer: Error: Cannot find module 'vue-native-scripts' ... _load (internal/modules/cjs/loader.js:746:27) at Module.require ...
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