ERROR in ./node_modules/discord-rpc/src/client.js 8:4-21
AlphaBeta906 opened this issue · comments
Hi,
I am using a React project using this RPC. I have seem to find an error here:
ERROR in ./node_modules/discord-rpc/src/client.js 8:4-21
Module not found: Error: Can't resolve 'timers' in '/Users/alphabeta906/Documents/BloodAlchemy/my-app/node_modules/discord-rpc/src'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
This is my webpack config:
module.exports = {
target: 'node',
entry: require.resolve('./src/index.js'),
resolve: {
fallback: { "timers": require.resolve("timers-browserify") }
},
};
Here is my code:
import { Client } from 'discord-rpc';
const client = new Client({
transport: 'websocket'
});
const setActivity = (data) => {
if (discord === true) {
client.setActivity(data);
}
}
const startTimestamp = new Date();
client.on('ready', () => {
setActivity({
details: user !== '' ? `Logged in as ${user}` : 'Logged in as Guest',
state: 'Doing Alchemy',
startTimestamp,
largeImageKey: 'logo',
largeImageText: 'Blood Alchemy RIP 2021-2022',
instance: false,
})
});
client.login('the client id');
It seems to work on node and on terminal, so it's a web only problem. I have also installed timers-browsify.
Thanks!
Apparently the issue was resolved due to the webpack config not updating.