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

Dealing with Uncaught Error: Cannot find module 'react' #145

onmyway133 opened this Issue Jan 17, 2018 · 0 comments


None yet
1 participant

onmyway133 commented Jan 17, 2018

This is my story through dealing with many dependencies when trying to package an electron app. Thanks to my friend for helping me out ❤️ This is like a note for my future self

Fixing event

The other I got an issue onmyway133/PushNotifications#3 that reports there's something wrong with production environment. The problem is that I used RadioButton and its onChange callback takes 2 parameters instead of 1.

Trying packaging

After the fix, I bump version in package.json and run yarn release. To my surprise, the built app was just blank. I tried win.toggleDevTools() to see what's going on. I can't use shortcut to open the dev tool any more in production, but there are tools

The console says that it can't find the module 'react'. I then submitted an issue electron-userland/electron-packager#787

Uncaught Error: Cannot find module 'react'

My environment

  • Node v8.4.0
  • npm 5.3.0
  • yarn 1.3.2
  • macOS 10.13.2

Inspecting with debug mode

I then need to run in debug mode to see what's really happening

DEBUG=electron-packager npm run release

The log says something about npm

Command failed: npm prune --production

Digging a little, I found that this is quite a common issue

I think the issue may be because of I changed from to

Updating nodenv

The latest stable version of is 8.9.4. To enable nodenv to see it, we need

brew upgrade node-build

Run the following so that you actually see the 8.9.4

nodenv install --list

Updating node.js

Install version 8.9.4

nodenv install 8.9.4
nodenv global 8.9.4
nodenv rehash

Updating npm

Run the following to update npm to 5.6.0

npm update -g np

Installing dependencies from scratch

Clear old node_modules and package-lock.json

rm -rf node_modules
rm -rf package-lock.json

Then install again

npm install


The final step is to package the app again

yarn release
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment