Skip to content
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

SyntaxError: Identifier 'self' has already been declared #4

Closed
DX37 opened this issue Nov 22, 2022 · 14 comments
Closed

SyntaxError: Identifier 'self' has already been declared #4

DX37 opened this issue Nov 22, 2022 · 14 comments
Assignees

Comments

@DX37
Copy link

DX37 commented Nov 22, 2022

Cannot run app:

> [email protected] start
> node src/index.js

/opt/jellyfin-discord-music-bot/jellyfin-discord-music-bot-fork/node_modules/jellyfin-apiclient/dist/jellyfin-apiclient.js:5
const self = require('window')
      ^

SyntaxError: Identifier 'self' has already been declared
    at internalCompileFunction (node:internal/vm:74:18)
    at wrapSafe (node:internal/modules/cjs/loader:1128:20)
    at Module._compile (node:internal/modules/cjs/loader:1169:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1259:10)
    at Module.load (node:internal/modules/cjs/loader:1068:32)
    at Module._load (node:internal/modules/cjs/loader:909:12)
    at Module.require (node:internal/modules/cjs/loader:1092:19)
    at require (node:internal/modules/cjs/helpers:103:18)
    at Object.<anonymous> (/opt/jellyfin-discord-music-bot/jellyfin-discord-music-bot-fork/src/jellyfinclientmanager.js:1:31)
    at Module._compile (node:internal/modules/cjs/loader:1205:14)
/opt/jellyfin-discord-music-bot/jellyfin-discord-music-bot-fork/node_modules/jellyfin-apiclient/dist/jellyfin-apiclient.js:5
const self = require('window')
      ^

SyntaxError: Identifier 'self' has already been declared
    at internalCompileFunction (node:internal/vm:74:18)
    at wrapSafe (node:internal/modules/cjs/loader:1128:20)
    at Module._compile (node:internal/modules/cjs/loader:1169:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1259:10)
    at Module.load (node:internal/modules/cjs/loader:1068:32)
    at Module._load (node:internal/modules/cjs/loader:909:12)
    at Module.require (node:internal/modules/cjs/loader:1092:19)
    at require (node:internal/modules/cjs/helpers:103:18)
    at Object.<anonymous> (/opt/jellyfin-discord-music-bot/jellyfin-discord-music-bot-fork/src/jellyfinclientmanager.js:1:31)
    at Module._compile (node:internal/modules/cjs/loader:1205:14)
@manuel-rw manuel-rw self-assigned this Dec 14, 2022
@manuel-rw
Copy link
Owner

manuel-rw commented Dec 14, 2022

Sorry, I didn't see your issue. I'll look into this as soon as I can

@manuel-rw
Copy link
Owner

Update:

I was able to reproduce this issue, but only if the jellyfin-apiclient package is being updated to a higher version.
Have you made any changes after pulling this repository?

I also noticed that there were some compile errors in the repo after pulling master - I fixed them.

@manuel-rw manuel-rw pinned this issue Dec 15, 2022
@DX37
Copy link
Author

DX37 commented Dec 16, 2022

Have you made any changes after pulling this repository?

No, I just built from repo with npm and wrote a config.js, nothing special.

@DX37
Copy link
Author

DX37 commented Dec 16, 2022

I guess somehow this issue was resolved. There's another, when I'm trying to summon bot:

/opt/containers/jellyfin-discord-music-bot/node_modules/discord.js/src/client/actions/MessageCreate.js:11
      const existing = channel.messages.cache.get(data.id);
                                        ^

TypeError: Cannot read properties of undefined (reading 'cache')
    at MessageCreateAction.handle (/opt/containers/jellyfin-discord-music-bot/node_modules/discord.js/src/client/actions/MessageCreate.js:11:41)
    at module.exports [as MESSAGE_CREATE] (/opt/containers/jellyfin-discord-music-bot/node_modules/discord.js/src/client/websocket/handlers/MESSAGE_CREATE.js:4:32)
    at WebSocketManager.handlePacket (/opt/containers/jellyfin-discord-music-bot/node_modules/discord.js/src/client/websocket/WebSocketManager.js:384:31)
    at WebSocketShard.onPacket (/opt/containers/jellyfin-discord-music-bot/node_modules/discord.js/src/client/websocket/WebSocketShard.js:444:22)
    at WebSocketShard.onMessage (/opt/containers/jellyfin-discord-music-bot/node_modules/discord.js/src/client/websocket/WebSocketShard.js:301:10)
    at WebSocket.onMessage (/opt/containers/jellyfin-discord-music-bot/node_modules/ws/lib/event-target.js:132:16)
    at WebSocket.emit (node:events:513:28)
    at Receiver.receiverOnMessage (/opt/containers/jellyfin-discord-music-bot/node_modules/ws/lib/websocket.js:1068:20)
    at Receiver.emit (node:events:513:28)
    at Receiver.dataMessage (/opt/containers/jellyfin-discord-music-bot/node_modules/ws/lib/receiver.js:517:14)

Node.js v19.2.0

I'll try it in Docker now.

@DX37
Copy link
Author

DX37 commented Dec 16, 2022

Same in Docker:

/app/node_modules/discord.js/src/client/actions/MessageCreate.js:11
      const existing = channel.messages.cache.get(data.id);
                                        ^

TypeError: Cannot read property 'cache' of undefined
    at MessageCreateAction.handle (/app/node_modules/discord.js/src/client/actions/MessageCreate.js:11:41)
    at Object.module.exports [as MESSAGE_CREATE] (/app/node_modules/discord.js/src/client/websocket/handlers/MESSAGE_CREATE.js:4:32)
    at WebSocketManager.handlePacket (/app/node_modules/discord.js/src/client/websocket/WebSocketManager.js:384:31)
    at WebSocketShard.onPacket (/app/node_modules/discord.js/src/client/websocket/WebSocketShard.js:444:22)
    at WebSocketShard.onMessage (/app/node_modules/discord.js/src/client/websocket/WebSocketShard.js:301:10)
    at WebSocket.onMessage (/app/node_modules/ws/lib/event-target.js:132:16)
    at WebSocket.emit (events.js:315:20)
    at Receiver.receiverOnMessage (/app/node_modules/ws/lib/websocket.js:1068:20)
    at Receiver.emit (events.js:315:20)
    at Receiver.dataMessage (/app/node_modules/ws/lib/receiver.js:517:14)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: `node src/index.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

Should I create another issue and close this since this error not related to old one?

@manuel-rw
Copy link
Owner

No, I just built from repo with npm and wrote a config.js, nothing special.

Do you mean a config.json?

I'll try it in Docker now.

You can build the container manually, but there is currently none published on a registry.

I guess somehow this issue was resolved. There's another, when I'm trying to summon bot:

I think this is an upstream error. But it's hard to verify, because the code of this bot is incredibly messy.
A few days ago, when I saw your issue, I actually got working on a complete rework of this:
https://github.com/manuel-rw/jellyfin-discord-music-bot/tree/nestjs-migration

It's not ready for use at all, but I'll give it a shot and try to migrate all the previous code.

@DX37
Copy link
Author

DX37 commented Dec 16, 2022

Do you mean a config.json?

Yeah, I accidentally skipped a few symbols :D

You can build the container manually, but there is currently none published on a registry.

That's what I did.

A few days ago, when I saw your issue, I actually got working on a complete rework of this: https://github.com/manuel-rw/jellyfin-discord-music-bot/tree/nestjs-migration

It's not ready for use at all, but I'll give it a shot and try to migrate all the previous code.

Oh, alright! I can test it, because interested in this kind of bot. And there isn't any other kind of Jellyfin Music Bot than this non working code...

@manuel-rw
Copy link
Owner

Oh, alright! I can test it, because interested in this kind of bot. And there isn't any other kind of Jellyfin Music Bot than this non working code...

That was exactly my problem too! The bot is honestly a bit cumbersome and there is a ton of stuff, I don't understand.
The most confusing thing is probably, that there is a ton of exceptions in hot paths, which cause your bot to totally crash and terminate - even if you use it as intended.
I'm not sure what the author's goal there was.

My ultimate goal is to completely migrate everything, but it's hard, because the old project is outdated and a ton of discord.js API changed.

@manuel-rw
Copy link
Owner

btw, feel free to try out the nestjs branch. Use at your work risk though :)
I probably won't invest much time into fixing existing bugs in the other branches.
If you can help pin pointing the error hindering you from using the old version, I'm happy to fix it

@DX37
Copy link
Author

DX37 commented Dec 16, 2022

God, I forgot.
I was trying to point npm to update discord.js. Got it updated from 12 to 14 major version and bug from first message happened. I just finally figured out how to uninstall old npm packages and install new ones according to semver in package.json.

Now I updated jellyfin-apiclient from fixed 1.7.0 to 1.10.0 and got another error:

> [email protected] start
> node src/index.js

ReferenceError: self is not defined
    at Object.<anonymous> (/opt/containers/jellyfin-discord-music-bot/node_modules/jellyfin-apiclient/dist/jellyfin-apiclient.js:1:224)
    at Module._compile (node:internal/modules/cjs/loader:1218:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1272:10)
    at Module.load (node:internal/modules/cjs/loader:1081:32)
    at Module._load (node:internal/modules/cjs/loader:922:12)
    at Module.require (node:internal/modules/cjs/loader:1105:19)
    at require (node:internal/modules/cjs/helpers:103:18)
    at Object.<anonymous> (/opt/containers/jellyfin-discord-music-bot/src/jellyfinclientmanager.js:1:31)
    at Module._compile (node:internal/modules/cjs/loader:1218:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1272:10)
ReferenceError: self is not defined
    at Object.<anonymous> (/opt/containers/jellyfin-discord-music-bot/node_modules/jellyfin-apiclient/dist/jellyfin-apiclient.js:1:224)
    at Module._compile (node:internal/modules/cjs/loader:1218:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1272:10)
    at Module.load (node:internal/modules/cjs/loader:1081:32)
    at Module._load (node:internal/modules/cjs/loader:922:12)
    at Module.require (node:internal/modules/cjs/loader:1105:19)
    at require (node:internal/modules/cjs/helpers:103:18)
    at Object.<anonymous> (/opt/containers/jellyfin-discord-music-bot/src/jellyfinclientmanager.js:1:31)
    at Module._compile (node:internal/modules/cjs/loader:1218:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1272:10)

And finally, because of orphaning original Jellyfin JS library and jellyfin-archive/jellyfin-apiclient-javascript#420 issue, I think they might be migrating to TypeScript actively now in https://github.com/jellyfin/jellyfin-sdk-typescript.

@manuel-rw
Copy link
Owner

Yes, I saw this issue too! I am using the new SDK in the nestjs-migration branch now, but I have trouble copying some code.
It will just take some time until I get it right...

@DX37
Copy link
Author

DX37 commented Dec 16, 2022

I'll leave this issue opened for now, so people at least can see what's happening with project.

@DX37
Copy link
Author

DX37 commented Dec 16, 2022

Oh, or not, because of #6

@manuel-rw
Copy link
Owner

Sure, no problem. You can subscribe to #6 so I can notify you for any changes if you want

@DX37 DX37 closed this as completed Dec 16, 2022
@manuel-rw manuel-rw unpinned this issue Dec 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants