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.

Module not found: Error: Can't resolve 'React' in '/home/capaj/project/node_modules/react-visibility-sensor/dist'

See original GitHub issue

I have webpack 4 and react-visibility-sensor 5.0.2 and when I import like this: import VisibilitySensor from "react-visibility-sensor" I get

ERROR in ../node_modules/react-visibility-sensor/dist/visibility-sensor.js
Module not found: Error: Can't resolve 'React' in '/home/capaj/git_projects/looop/project-alpha/node_modules/react-visibility-sensor/dist'
 @ ../node_modules/react-visibility-sensor/dist/visibility-sensor.js 4:286-324
 @ ./src/pages/student-topic-detail-page/StudentTopicDetailPage.tsx
 @ ./src/components/LooopRoutes.tsx
 @ ./src/components/App.js
 @ ./src/app/app.js
 @ ./src/index/index.js
 @ multi webpack-dev-server/client?http://localhost:4001 webpack/hot/dev-server ./src/index/index

ERROR in ../node_modules/react-visibility-sensor/dist/visibility-sensor.js
Module not found: Error: Can't resolve 'ReactDOM' in '/home/capaj/git_projects/looop/project-alpha/node_modules/react-visibility-sensor/dist'
 @ ../node_modules/react-visibility-sensor/dist/visibility-sensor.js 4:286-324
 @ ./src/pages/student-topic-detail-page/StudentTopicDetailPage.tsx
 @ ./src/components/LooopRoutes.tsx
 @ ./src/components/App.js
 @ ./src/app/app.js
 @ ./src/index/index.js
 @ multi webpack-dev-server/client?http://localhost:4001 webpack/hot/dev-server ./src/index/index

when I change to import the source file: import VisibilitySensor from 'react-visibility-sensor/visibility-sensor'

it works great.

The webpack thingy seems to think I the app run in an UMD loader and hence it tries to load deps from globals.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:5
  • Comments:15

github_iconTop GitHub Comments

8reactions
autolistbencommented, Mar 26, 2019

Actually on second thought, it is better to configure webpack to skip transpilation for react-visibility-sensor instead of importing what is essentially a private file. If this package changed its file structure that could cause your code to crash. So instead configure babel-loader as follows and leave your imports and jest config alone!

{
  test: /\.js?$/,
  use: {
    loader: 'babel-loader',
    options: {
      cacheDirectory: true
    }
  },
  exclude: /node_modules\/react-visibility-sensor\/.*/
}
7reactions
naoyeyecommented, Dec 26, 2018

import VisibilitySensor from 'react-visibility-sensor/visibility-sensor'

saving my life!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Module not found: Can't resolve 'react' - Stack Overflow
I'm trying to connect my Redux store to my React project, but I keep getting this error:.
Read more >
Module not found: Can't resolve 'X' error in React | bobbyhadz
The error "Module not found: Can't resolve" occurs for multiple reasons in React: Importing a local file from an incorrect relative path. Forgetting...
Read more >
module not found error | can not resolve react dom module
Join this channel to get access to perks:https://www.youtube.com/channel/UCoSpmr2KNOxjwE_B9ynUmig/joinMy GearCamera ...
Read more >
Module not found: Error: Can't resolve 'stream' in React project ...
I believe changing react-scripts to 4.0.3 and rerunning yarn install or npm install would've fixed this issue. There are several ways to get...
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