discordjs / RPC

A simple RPC client for Discord

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error when attempting to use with Webpack

chakany opened this issue · comments

I am getting an error whenever I try to use the library in my app. I am using the Electron-Forge Typescript + Webpack Template.

This is my error:

Uncaught Exception:
Error: Module build failed (from ./node_modules/@marshallofsound/webpack-asset-relocator-loader/dist/index.js):
SyntaxError: Unexpected token (48:12)
    at Object.module.exports.pp$4.raise (/home/jacany/launcher/node_modules/@marshallofsound/webpack-asset-relocator-loader/dist/index.js:20834:13)
    at Object.module.exports.pp.unexpected (/home/jacany/launcher/node_modules/@marshallofsound/webpack-asset-relocator-loader/dist/index.js:18680:8)
    at Object.module.exports.pp$1.parseTryStatement (/home/jacany/launcher/node_modules/@marshallofsound/webpack-asset-relocator-loader/dist/index.js:19069:49)
    at Object.module.exports.pp$1.parseStatement (/home/jacany/launcher/node_modules/@marshallofsound/webpack-asset-relocator-loader/dist/index.js:18834:32)
    at Object.parseStatement (/home/jacany/launcher/node_modules/@marshallofsound/webpack-asset-relocator-loader/dist/index.js:4539:118)
    at Object.parseStatement (/home/jacany/launcher/node_modules/@marshallofsound/webpack-asset-relocator-loader/dist/index.js:42314:22)
    at Object.module.exports.pp$1.parseBlock (/home/jacany/launcher/node_modules/@marshallofsound/webpack-asset-relocator-loader/dist/index.js:19157:23)
    at Object.module.exports.pp$3.parseFunctionBody (/home/jacany/launcher/node_modules/@marshallofsound/webpack-asset-relocator-loader/dist/index.js:20675:22)
    at Object.module.exports.pp$3.parseMethod (/home/jacany/launcher/node_modules/@marshallofsound/webpack-asset-relocator-loader/dist/index.js:20616:8)
    at Object.module.exports.pp$1.parseClassMethod (/home/jacany/launcher/node_modules/@marshallofsound/webpack-asset-relocator-loader/dist/index.js:19379:23)
    at Object.parseClassMethod (/home/jacany/launcher/node_modules/@marshallofsound/webpack-asset-relocator-loader/dist/index.js:35838:39)
    at Object.parseClassMethod (/home/jacany/launcher/node_modules/@marshallofsound/webpack-asset-relocator-loader/dist/index.js:15917:44)
    at Object.parseClassMethod (/home/jacany/launcher/node_modules/@marshallofsound/webpack-asset-relocator-loader/dist/index.js:302:42)
    at Object.module.exports.pp$1.parseClassElement (/home/jacany/launcher/node_modules/@marshallofsound/webpack-asset-relocator-loader/dist/index.js:19368:8)
    at Object.parseClassElement (/home/jacany/launcher/node_modules/@marshallofsound/webpack-asset-relocator-loader/dist/index.js:35821:40)
    at Object.parseClassElement (/home/jacany/launcher/node_modules/@marshallofsound/webpack-asset-relocator-loader/dist/index.js:15838:56)
    at Object../node_modules/discord-rpc/src/transports/websocket.js (/home/jacany/launcher/.webpack/main/index.js:2050:7)
    at __webpack_require__ (/home/jacany/launcher/.webpack/main/index.js:21:30)
    at Object../node_modules/discord-rpc/src/transports/index.js (/home/jacany/launcher/.webpack/main/index.js:1852:14)
    at __webpack_require__ (/home/jacany/launcher/.webpack/main/index.js:21:30)
    at Object../node_modules/discord-rpc/src/client.js (/home/jacany/launcher/.webpack/main/index.js:950:20)
    at __webpack_require__ (/home/jacany/launcher/.webpack/main/index.js:21:30)
    at Object../node_modules/discord-rpc/src/index.js (/home/jacany/launcher/.webpack/main/index.js:1831:11)
    at __webpack_require__ (/home/jacany/launcher/.webpack/main/index.js:21:30)
    at Object../src/utils/discord.ts (/home/jacany/launcher/.webpack/main/index.js:4250:37)
    at __webpack_require__ (/home/jacany/launcher/.webpack/main/index.js:21:30)

This is my code:

import * as DiscordRPC from "discord-rpc";

// Set this to your Client ID.
const clientId = "myclientid";

const startTimestamp = new Date();

class discord {
	rpc: DiscordRPC.Client;
	constructor() {
		DiscordRPC.register(clientId);

		this.rpc = new DiscordRPC.Client({ transport: "websocket" });

		this.rpc.on("ready", () => {
			this.setActivity({
				details: "Text",
				startTimestamp,
				largeImageKey: "logo",
				largeImageText: "Text",
				instance: false,
			});
		});

		this.rpc.login({ clientId }).catch(console.error);
	}

	setActivity(activity: DiscordRPC.Presence): void {
		this.rpc.setActivity(activity);
	}
}

const rpc = new discord();

export default { rpc };

Anyone know what's up?

Just for you to know, 'websocket' is a discord whitelisted transport method, so it wont work if your app isn't whitelisted

Just for you to know, 'websocket' is a discord whitelisted transport method, so it wont work if your app isn't whitelisted

Well, I guess there is no point in trying to use it anyway then. Thanks.