ByzantineFailure / BPM-for-Discord

BPM for Discord's Desktop App. Includes one-click installers, update notifications, and custom script support.
GNU Affero General Public License v3.0
17 stars 8 forks source link

Javascript Error when installing under Linux #59

Closed eyecikjou567 closed 6 years ago

eyecikjou567 commented 7 years ago

After installing BPM4D successfully (according to the installer) on Arch-Linux, discord will hang at startup indefinitely with the following error message:

A JavaScript error occurred in the main process
Uncaught Exception:
Error: Cannot find module 'discord_toaster'
    at Module._resolveFilename (module.js:455:15)
    at Function.Module._resolveFilename (/opt/discord-canary/resources/electron.asar/common/reset-search-paths.js:35:12)
    at Function.Module._load (module.js:403:25)
    at Module.require (module.js:483:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/opt/discord-canary/resources/app.asar/app/NotificationWindow.js:37:24)
    at Module._compile (module.js:556:32)
    at Object.Module._extensions..js (module.js:565:10)
    at Module.load (module.js:473:32)
    at tryModuleLoad (module.js:432:12)
ByzantineFailure commented 7 years ago

@eyecikjou567 I realize this feels like an odd question, but did discord load properly before installing BPM? discord_toaster is a built-in discord module that handles notifications on the desktop. If it doesn't I may ask you to do some surgery on the asar file to link me a particular file and see what went wrong in injection.

eyecikjou567 commented 7 years ago

It does load properly before installing, no error or anything.

DiscordCanary 0.0.11
[Modules] Modules initializing
[Modules] Distribution: remote
[Modules] Host updates: enabled
[Modules] Module updates: enabled
[Modules] Install path: /home/$USER/.config/discordcanary/0.0.11/modules
[Modules] No updates to install
[Modules] Checking for host updates.
[Modules] Host is up to date.
[Modules] Checking for module updates at https://discordapp.com/api/modules/canary/versions.json
[Modules] No module updates available.
Initializing voice engine [legacy device: false]

I tried the installation with both the legacy nodejs that the installer downloads and the installed nodejs runtime.

Might be noteworthy that I have to run the installed with sudo since discord is installed under /opt/discord-canary

Here is the installer log:

[sudo] Passwort für $USER: 
Could not find node of version v4.2.x, found node version v7.2.0. What would you like to do?
1) Download correct node and install  3) Exit
2) Install using local version
#? 1
Downloading standalone tarball...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 11.2M  100 11.2M    0     0   312k      0  0:00:36  0:00:36 --:--:--  310k
Unpacking node...
node-v4.2.4-linux-x64/bin/node
Please enter the install directory
/opt/discord-canary
Installing to /opt/discord-canary
{ _: [ '/home/$USER/Downloads/discord' ],
  p: '/opt/discord-canary' }
Paths results are:
{
 "discordExtract": "/opt/discord-canary/resources/bpm_extract",
 "discordPack": "/opt/discord-canary/resources/app.asar",
 "discordBackup": "/opt/discord-canary/resources/app.asar.clean",
 "integrationSource": "/home/$USER/Downloads/discord/integration.asar",
 "addonSource": "/home/$USER/Downloads/discord/bpm.js",
 "addonDirectory": "/opt/discord-canary/bpm",
 "addonTarget": "/opt/discord-canary/bpm/bpm.js",
 "addonCustom": "/opt/discord-canary/bpm/custom",
 "addonCustomBackup": "/opt/bpm_custom.bak"
}
Pre-existing app.asar.clean found, using that...
Extracting app.asar from /opt/discord-canary/resources/app.asar.clean ...
App extraction complete!
Injecting package dependency...
Package dependency injected
Moving integration into node_modules...
Done extracting integration!
Injecting BPM code into index.js...
BPM Injected!
Packing injected asar...
Backing up old custom scripts to /opt/bpm_custom.bak
Done backing up old custom scripts
Removing previous bpm, if it exists...
Removed previous bpm!
Extracting bpm data to discord data...
Done extracting bpm data
Restoring old custom scripts
Restored old custom scripts to /opt/discord-canary/bpm/custom
Install complete!
Packing complete!
Cleaning up unpacked data...
Cleaned up unpacked data.
Removing node tarball and extract...

The /opt/discord-canary/resources/modules folder does also contain a discord_toaster.zip if that helps.

ByzantineFailure commented 7 years ago

That's... interesting. Could you try making sure the permissions on the app.asar and other discord files are set up properly so that the user running discord can read them?

Maybe just toss +rw on the whole thing recursively?

eyecikjou567 commented 7 years ago

I tried a chmod --recursive +rw * on the entire directory, sadly it did not help. The error continues to occur.

ByzantineFailure commented 7 years ago

Okay, so, repro steps are:

  1. Install discord-canary to /opt/ -- did you do this using sudo?
  2. Install BPM with sudo
  3. See error occur.
ByzantineFailure commented 7 years ago

What's interesting is that the line it fails on is this: var _discord_toaster = require('discord_toaster');

Electron itself cannot resolve this path, and I am not sure why.

Serious question, can you try putting Discord somewhere other than /opt (extract a fresh copy to somwhere like ~/discord as your user, not sudo'd), then try and run the installer not sudo'd? I'm leaning towards this being a permissions issue.

ByzantineFailure commented 7 years ago

Note: I can't actually repro this myself as my linux box runs completely headless and Discord requires a window manager/X Session to be available before it starts.

eyecikjou567 commented 7 years ago

So I've just tried as you suggested, although I suspect it's more than a simple permission issue.

When installing to ~/discord and then running the installer it works quite well (after a couple retries due to my ineptitude).

However, when I do sudo cp -R ~/discord/* /opt/discord-canary, thusly creating all files with owner as root, the install continues to function normally.

It might be that discord is downloading updates elsewhere and thusly the installer is overwriting an outdated version of discord...

I think I'll simply put the canary on the "don't update" list and hope that works.

ByzantineFailure commented 7 years ago

@eyecikjou567 That's... weird. Well, this is something I'll need to address at some point, probably when the linux client gets out of beta/canary/whatever they're calling it and is a proper release.

Keeping this issue open as I should keep an eye on it.

ByzantineFailure commented 7 years ago

@eyecikjou567 have you seen this reproduce lately?

eyecikjou567 commented 7 years ago

Sadly not, I've been using a modloader (not BetterDiscord) to load BPM into discord lately, I guess this could be closed if noone else has this problem unless you want to keep it open.

ByzantineFailure commented 6 years ago

Closing due to lack of activity. Please feel free to re-open if this repros.

KresimirCosic commented 4 years ago

Hey, I also had the JavaScript error happen on Pop!_OS after removing Discord and installing it again. I did it because the minimize, maximize and close button bar has suddenly disappeared from the app (reinstall didn't help).

I resolved my issue by uninstalling via CLI:

sudo apt remove discord sudo apt autoremove

Then I deleted the folder:

~/.config/discord/

Then I reinstalled the app via CLI:

sudo apt install discord

And I started the app via CLI as well by running:

discord

The startup started, and said there was an update, so it automatically started downloading a file via my browser, which I installed via Debian installer (by just double clicking the file when it finished downloading, mind you the CLI Discord PID is still running I haven't turned it off yet with Ctrl + C). After it finished installing that update file I was able to start it up successfully again - still not resolving my first issue, the missing top bar with window buttons.

Hope it helps someone.