electron / packager

Customize and package your Electron app with OS-specific bundles (.app, .exe, etc.) via JS or CLI
https://npm.im/@electron/packager
BSD 2-Clause "Simplified" License
124 stars 11 forks source link

Uncaught Error: Cannot find module 'react' when using npm 5.3.0 #787

Closed onmyway133 closed 6 years ago

onmyway133 commented 6 years ago

Hi, I was using electron-packager in my app https://github.com/onmyway133/PushNotifications and it was working fine. Now I want to make new release, but all I get is

Uncaught Error: Cannot find module 'react'
    at Module._resolveFilename (module.js:470:15)
    at Function.Module._resolveFilename (/Users/khoa/XcodeProject2/PushNotifications/PushNotifications-darwin-x64/Pu…tions.app/Contents/Resources/electron.asar/common/reset-search-paths.js:35:12)
    at Function.Module._load (module.js:418:25)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/Users/khoa/XcodeProject2/PushNotifications/PushNotifications-darwin-x64/PushNotifications.app/Contents/Resources/app/renderer.js:2:15)
    at Object.<anonymous> (/Users/khoa/XcodeProject2/PushNotifications/PushNotifications-darwin-x64/PushNotifications.app/Contents/Resources/app/renderer.js:16:3)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)

I don't know if this is a duplicate of https://github.com/electron-userland/electron-packager/issues/517, but I can't find an answer from that thread.

When I run (with yarn start), it is working fine. When I run yarn release, it just shows a blank app with the above error. I tried upgrade react, electron, ... but still the problem. Here is my package.json https://github.com/onmyway133/PushNotifications/blob/master/package.json

My environment

welcome[bot] commented 6 years ago

👋 Thanks for opening your first issue here! If you have a question about using Electron Packager, read the support docs. If you're reporting a 🐞 bug, please make sure you include steps to reproduce it. Development and issue triage is community-driven, so please be patient and we will get back to you as soon as we can.

To help make it easier for us to investigate your issue, please follow the contributing guidelines.

MarshallOfSound commented 6 years ago

Try upgrading yarn (what version are you running now)

onmyway133 commented 6 years ago

@MarshallOfSound Hi, this problem happens before and after I update yarn. My current version is v1.3.2

malept commented 6 years ago

I can't reproduce this on Linux. When I run the packaged app, I get the same screen as in the screenshot in your repo's README. Here's how I did it:

$ git clone https://github.com/onmyway133/PushNotifications
$ cd PushNotifications
$ yarn
$ yarn run release
$ PushNotifications-linux-x64/PushNotifications

My yarn is also at 1.3.2.

Can you try with a fresh git checkout of your repo?

onmyway133 commented 6 years ago

@malept I tried a fresh git clone, and still the problem 😢

malept commented 6 years ago

Can you try building on another computer or in a Linux VM? I'm concerned that your environment is incorrectly configured somehow.

pixelkritzel commented 6 years ago

I had this problem with another dependency. I kind of solved by using npm@3 instead of npm@5. It seems there is a bug in npm@5 prune command

malept commented 6 years ago

@pixelkritzel this issue is a yarn specific bug.

pixelkritzel commented 6 years ago

Sorry, my bad.

onmyway133 commented 6 years ago

@malept I tried running npm run release but still the problem. So it shouldn't be because of yarn ?

onmyway133 commented 6 years ago

When I run in debug mode DEBUG=electron-packager npm run release, I get


> PushNotifications@1.2.2 release /Users/khoa/XcodeProject2/PushNotifications
> electron-packager . --icon=Icon/Icon.icns

  electron-packager Electron Packager 10.1.1 +0ms
  electron-packager Node v8.4.0 +2ms
  electron-packager Host Operating system: darwin (x64) +0ms
  electron-packager Packager Options: {"_":["."],"all":false,"deref-symlinks":true,"derefSymlinks":true,"download":{"strictSSL":true},"overwrite":false,"prune":true,"quiet":false,"icon":"Icon/Icon.icns","dir":".","protocols":[]} +0ms
  electron-packager Target Platforms: darwin +0ms
  electron-packager Target Architectures: x64 +0ms
  electron-packager Inferring application name from productName in /Users/khoa/XcodeProject2/PushNotifications/package.json +0ms
  electron-packager Inferring appVersion from version in /Users/khoa/XcodeProject2/PushNotifications/package.json +0ms
  electron-packager Inferring target Electron version from electron in /Users/khoa/XcodeProject2/PushNotifications/package.json +11ms
  electron-packager Application name: PushNotifications +23ms
  electron-packager Target Electron version: 1.7.10 +0ms
  electron-packager Ignored path regular expressions: [ '/node_modules/electron($|/)',
  '/node_modules/electron-prebuilt(-compile)?($|/)',
  '/node_modules/electron-packager($|/)',
  '/\\.git($|/)',
  '/node_modules/\\.bin($|/)',
  '\\.o(bj)?$' ] +0ms
  electron-packager Downloading Electron with options {"strictSSL":true,"platform":"darwin","arch":"x64","version":"1.7.10"} +0ms
Packaging app for platform darwin x64 using electron v1.7.10
  electron-packager Creating /var/folders/wq/4p3h9g5d4v53gkz0k7xl11dr0000gn/T/electron-packager/darwin-x64-template +227ms
  electron-packager Extracting /Users/khoa/.electron/electron-v1.7.10-darwin-x64.zip to /var/folders/wq/4p3h9g5d4v53gkz0k7xl11dr0000gn/T/electron-packager/darwin-x64-template +0ms
  electron-packager Initializing app in /var/folders/wq/4p3h9g5d4v53gkz0k7xl11dr0000gn/T/electron-packager/darwin-x64/PushNotifications-darwin-x64 from /var/folders/wq/4p3h9g5d4v53gkz0k7xl11dr0000gn/T/electron-packager/darwin-x64-template template +0ms
  electron-packager Ignored paths based on the out param: [ '/Users/khoa/XcodeProject2/PushNotifications/PushNotifications-darwin-x64',
  '/Users/khoa/XcodeProject2/PushNotifications/PushNotifications-linux-ia32',
  '/Users/khoa/XcodeProject2/PushNotifications/PushNotifications-linux-x64',
  '/Users/khoa/XcodeProject2/PushNotifications/PushNotifications-linux-armv7l',
  '/Users/khoa/XcodeProject2/PushNotifications/PushNotifications-linux-arm64',
  '/Users/khoa/XcodeProject2/PushNotifications/PushNotifications-mas-x64',
  '/Users/khoa/XcodeProject2/PushNotifications/PushNotifications-win32-ia32',
  '/Users/khoa/XcodeProject2/PushNotifications/PushNotifications-win32-x64' ] +2s
  electron-packager Pruning modules via: npm prune --production +0ms
Command failed: npm prune --production
npm ERR! May not delete: /private/var/folders/wq/4p3h9g5d4v53gkz0k7xl11dr0000gn/T/electron-packager/darwin-x64/PushNotifications-darwin-x64/Electron.app/Contents/Resources/app/node_modules/.bin

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/khoa/.npm/_logs/2018-01-17T14_43_41_288Z-debug.log

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! PushNotifications@1.2.2 release: `electron-packager . --icon=Icon/Icon.icns`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the PushNotifications@1.2.2 release script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/khoa/.npm/_logs/2018-01-17T14_43_41_339Z-debug.log

It says

Command failed: npm prune --production

So maybe it's related to https://github.com/electron-userland/electron-packager/issues/686

onmyway133 commented 6 years ago

Here is my story https://github.com/onmyway133/blog/issues/145. Hope it helps someone

onmyway133 commented 6 years ago

I think I get this same problem, but on Linux build https://github.com/onmyway133/IconGenerator/issues/4. Any help would be appreciated

malept commented 6 years ago

Try using --no-package-manager.