Can't get working in Deno
I've been told Sapphire works in Deno, but when I tried to run my project as-is, I get this error.
Solution:Jump to solution
I'm going to use this message to mark as resovled with @Answer Overflow. The TL;DR is that Deno's node modules compatibility is kind of garbage and the solutions are
- Stick to NodeJS. @vladdy and I are of the opinion that OP's issues with Node can be solved with Node, it just requires some environment setup.
- Use Bun instead of Deno, we fully support it and it does have proper support for node modules....
141 Replies
Does it also run in Node.js?
It works fine with Node
I deleted my old node_modules and dist folders and now it works, but I do see "Warning: Not implemented: ClientRequest.options.createConnection"
Should I be concerned about this?
.....the bot also isn't responding to any commands.
ApplicationCommandRegistries: Took 0ms to initialize.yeah, i think it's looking for javascript files and not properly accounting for typescript files?
also this
Are you loading TS files directly? I think we might need to add some code for that still but none of us have installed / used deno before to analyse what to add.
Here specifically https://github.com/sapphiredev/pieces/blob/main/src/lib/strategies/LoaderStrategy.ts#L41-L44
For funsies you could try setting that env var mentioned there manually and see what happens
But other than that if you can provide a repro sample then we can add proper deno support
As for djs not exporting LocaleString, that would suggest you're using an outdated version of DiscordJS or Deno does something really weird and ecosystem incompatible with handling s package that re-exports from other packages. LocaleString is re-exported in discordjs from discord-api-types/v10
If you have a package.json (which I do in this case), it uses the module versions in there.
Well is it the latest
14.14.1
sorry i thought that was a statement, not a question. it's
~14.14.1
in package.json
also, i tried setting TS_NODE_DEV. i'm pretty it did load the files, unlike before, since i got a bunch of import errors that i had to fix, but the commands still don't work and it still says it took 0ms to initialize.bump because I want to look into this still
This is where I'm at now. @vladdy we should fix Deno support tbh. No idea yet why it picks up 1 command many times nor why it fails to load CoreReady.
Ugh... Deno support will be hell compared to bun
https://github.com/sapphiredev/pieces/pull/373 at least one thing I noticed
GitHub
fix: add deno to the filters for loading TS files by favna Ā· Pull R...
This is at least one thing that's required, aside from any other issues that need to be fixed to add Deno support.
Did you get the same errors as me @Ruin š² ?
I wonder if the registry is somehow affected or if the piece is just loaded multiple times
If you can get me a minimum repro I can take a look when I'm back
And I've got some time
Also does deno import esm or cjs of our module
ESM
Phew
But does it import esm or cjs of pieces
When you import framework
esm again
GitHub
GitHub - favna/sapphire-deno-repro: A tiny repro for sapphire + deno
A tiny repro for sapphire + deno. Contribute to favna/sapphire-deno-repro development by creating an account on GitHub.
Ty
As for the bottom error that it fails to unload CoreReady, for some reason it tried to unload it twice
damn, we had the same issue with bun iirc
but thats related to the piece being loaded twice
we fix that, we fix the error
Nope. I listed out all the errors I had. Fwiw, I also had issues with i13n ( https://discord.com/channels/737141877803057244/1193004162967928902/1193063221502943372 ), so you may want to add that to the repro repo. Maybe in a different branch so you can focus on base functionality first.
yeahhh we have the repo above ^
once we fix that, it should all be gud
Yeah, I was saying to add code for i13n to that repo, probably in a different branch.
(also cute PFP o3o)
Anyways, I'll try to pull myself away from GTA V to test the latest Sapphire version.
Is there a way to have Sapphire output verbose?
FYI it's I18n not 13. The 18 refers to the amount of letters between the I and the N in the word internationalisation
Likewise it's l10n for localisation and k8s for kubernetes
mistype
See the src/main.ts in my repo logger config
All good. Some people don't know what the number represents so I was making sure.
i knew what the 18 was. i just didn't bother checking if the number was correct. lol
deno still doesn't find any commands for me btw
I did explicitly add
"@sapphire/pieces": "^4.2.1"
to my package.json
You will probably need to add resolutions so that framework uses that version.
deno deduplicates and symlinks I saw in my repo
but you do have to delete node_modules and deno.lock then restart for that
you can also --unstable-byonm (Bring Your Own Node Modules) to use the packages npm / pnpm installs.
btw, should someone pin the repro link?
oh.
i figured out why it can't find my commands.That doesn't quite explain why I get more errors than you still tho
I mean, this is Deno reading the command files multiple times for some reason.
hmm actually
Loaded 1 commands.
Well maybe that'll happen for you now as well
Yeah that's logged for me too
But then it API errors
actually, it registered commands just fine on my project.
Pls share your project tbh
funny thing is i've been working to make it public.
was previously a specialized bot for a single server with a bunch of hardcoded values.
granted, idk if the project would work with a new bot. the commands are already registered.
I mean thats @Gemboard as well but that didn't stop me from making it open source š
I love how deno task start just hangs on fetching snowflake
Not for me...
eh, a restart worked
also denos lsp does NOT like our sapphire/framework imports
wth
Relative import path "@sapphire/framework" not prefixed with / or ./ or ../
Worked fine for me after adding the plugin and running the bot once to build the modules
oh uh
Might have to reload once
ye i did restart the LSP
just published my repo and immediately got this system message
did you commit your token
Lmao published a token
Happens to the best of us
i think it was an old commit
Have fun resetting the token
yep
its already reset
thats what the system message is for
It tells you to obtain a new token not that the current token has been nuked...
oh fuck the prod bot is broken
favna
pls
GitHub
GitHub - RuiNtD/GumroadBot at deno
Contribute to RuiNtD/GumroadBot development by creating an account on GitHub.
whatever here's the thing
Oh
"our token-scanning gremlins noticed, and have reset your bot's token"
idek if it works on a new bot. all i tried was on my existing dev bot (with the same commands) and tried renaming one of my commands.
why tf does it not rebuild if i changed a file
Uhm you don't actually use deno if you use pnpm?
whos that to
Ruin
...oh god
so
deno can use the modules in node_modules
funny thing
that's why there's a
"byonm"
flag in deno.jsonc
Yeah but you also don't call deno run
You call pnpm
i just call
deno run
from CLI.Oh it's not in your package.json like it is for my repo
That's what threw me off
yeah this is a half converted node project
ok fun fact: deno doesnt cache imports
i'm trying to use deno because i fucking hate node
why
to both of those statements
version management
and it'd be easier to update prod
Maybe try Bun instead? We should definitely support that now
version management
has nothing to do with nodealso
package management, having to update the packages every time i push to prod
if you import store from pieces directly, its a different instance than the Store exported from framework
wtaf deno
not true either
am on windows
between npm ci, yarn and pnpm, all support just installing w/e is in the lockfile and strictly that
I mean WSL.. But yes that's a pita
WHY IS WALK GETTING CALLED TWICE ON STORES
i just prefer being able to
git fetch
, git pull
and just run the updated codeand you can do that...with node
and if you update dependencies you SHOULD manually run the cmd
As for package versions, works just fine for me for bots. I use renovate to autobump them then I have a GitHub workflow that pushes a new docker file image and I can (but haven't set it up yet) then also auto restart the prod bot. Fully automated.
anyways back to the issue at hand
walk is called twice
register is only called ONCE
so w t h
time to add a shit ton more debugging instead of using breakpoints like a sane person? ĀÆ\_(ć)_/ĀÆ
that's what i do
no i'm not okay
oh i dont swing that way, I throw in console.logs in
ayoooooo
yes favna, sue me
I've been tryign to teach vladdy to use breakpoints for years now
I still haven't succeeded
see the thing is
I do use breakpoints
when I want to
I dont want to rn
so I dont
dont like it dont care didnt ask
oh no
I see the issue I think
oh for FUCK SAKE
oh no
guess what i found
code?
a nested node modules folder inside framework
which has its OWN PIECES VERSION
of the spaghetti variety perhaps?
it's symlinked tho
Then explain to me why this happened
the only place that logs that is in Store#loadPath
first thing before logging that, I injected a log for the stack
and only 1 stacktrace came
wait wtf
the symlinks are there
HOW CAN THERE BE TWO CALLS
does deno follow symlinks by default?
like how node has
--follow-symlinks
HOW IS LOADPATH BEING CALLED WITH MY INJECTED CODE BUT ALSO NOT
WHAT
this makes no sense
ffs favna
did you really setup the debug binary to be HOMEBREW DENO
why are you not using homebrew
but anyway I just copypastad code from elsewhere lol
why tf would i use homebrew for a runtime that has its own updater and everything
same with bun
just use their sh script
I would never
brew --update && brew --upgrade
is too nicefirst off
brew upgrade
which does both
lol
I very much treat brew like apt and just use it for like .. nearly everything
fair
oh god the debugger does NOT like our promise.all
lol
w t f is happening
oh thats why its logged twice
ok so the double logging is correct and fine
oh interesting, we have some core listeners that load twice
yeah I noticed that with CoreReady because it got unloaded twice, the second one failing because it's gone already
but why
we had this issue with...cjs being loaded alongside esm but that shouldn't happen
maybe paths arent being loaded correctly because of the symlinks?
check what paths it tries to load?
well they are virtual pieces
so
who tf knows
hm
I'll slap some ddebugs into that
also funnily enough
not all core pieces dupe
just some
the loader is called twice
...why
why is our _load.mjs called twice
..oh my god wait
oh my god wait
is it bc we import framework twice???
wdym import it twice?
that would go handinhand with deno not caching tho
once in setup, once in main
well good news
its not that
try moving all the setup stuff to mai..
funn
so
i moved it all to root
now it just
dies
so this must be some deno issues with imports
in which case we're le fucked
I can fix it at the virtual piece level by..making it a map and not an array, so core pieces with the same name dont duplicate
but
deno is mega broken
It's hell to refactor but maybe do what they do here with deps.ts to cache them?
i just..
man
thats so janky
I'll try
nop, i completely fucked it now
welp
tl;dr: use bun instead of deno lol
or just stick to whats known to work (node)
also open an issue about this to their repo.. i doubt they'd fix it but who knows
but I have a fix for now
weeeellll now it didnt...load commands???
NOW THE DEFAULT BEHAVIOR DOESNT CHANGE
are you actually changing stuff or is it flaky lol
no at this point its just what the repo has
and its not setting the mode to bulk overwrite
even tho the file is called
IT JUST RESET
oh my god
or its a different context, in which case tough luck
holy shit deno
it's kind of ironic dont you think that the creator of node rags on about mistakes made with node, then makes deno, and makes it a total clusterfuck
its because their impl of npm support is a clusterfuck
deno itself as a runtime is FINE
use it in its ecosystem and you're FINE
BUT they half assed the fuck out of node support
and here i was moaning that bun was bitchy
I dont even know how to describe this behavior to them to ask them to fix it..
btw this could be related to i18n not working
Yeah there's not much we can do, their npn support is hella borked
We recommend either going bun or just sticking to node
Did you create a Deno issue?
.
Solution
I'm going to use this message to mark as resovled with @Answer Overflow. The TL;DR is that Deno's node modules compatibility is kind of garbage and the solutions are
- Stick to NodeJS. @vladdy and I are of the opinion that OP's issues with Node can be solved with Node, it just requires some environment setup.
- Use Bun instead of Deno, we fully support it and it does have proper support for node modules.
Uhmm, need to open an age old thread. I see no errors, my console just says
I have a ping command in the
commands
directory which does not seem to load example from the docs https://sapphirejs.dev/docs/Guide/getting-started/creating-a-basic-app-command
Steps I followed to setup the project in deno.
Step 1: deno init
Step 2: deno add npm:@sapphire/framework npm:[email protected]
Step 3: Created src/main.ts
.
Step 4: Created commands/ping.ts
with the above slash command example shared.
Step 5: Made a listeners/ready.ts
(because earlier the slash command or prefix based command would just not work, I also ensured that loadMessageCommandListeners
was enabled when checking via prefix
based)
Still now it does not emit ready.ts
with the message.
Minimal Repo Link: https://github.com/anishshobithps/discord-deno-test
Note: I have read solutions marked before asking users to use either node
or bun
but now that deno have released support for npm packages in the v2 I wanted to see if deno is gonna work now.I suspect it's base user directory detection going wrong and you can fix it by adding a
package.json
file. What does process.cwd()
give?
See also https://github.com/sapphiredev/pieces/blob/c2105ee9eb890f84e4b1bb2f07630f34893c6a00/src/lib/internal/RootScan.ts#L78I think yeah
package.json
was probably the culprit here. I fixed by doing the following steps
1. Deleted deno-lock.json
, deno.json
.
2. Did npm init -y
3. Installed all the required modules
4. Added deno.json
back to define tasks
Worked fine after this, caused a bit issue when it came to the Deno.env
part but adding "deno.enable": true
in .vscode/settings.json
fixed the issue.
Not required but I then just deleted package-lock.json
and node_modules
and ran deno install
and it worked fine after this as well.
I have the pushed the working example to the above github repo I linked.
Update: Uhmm seems like autocomplete is completely broken, disabling deno.enable
gets its back but things like Deno.readFile
, Deno.env
just throws errors on the editor. Seems like there is no proper fix as of right now. I'll stick to Node for time being.