JS Example has error with loading routes
I've downloaded the JS example from here: https://github.com/sapphiredev/examples/tree/main/examples/with-javascript
The bot runs fine apart from a few issues with loading the routes
and
Not sure what's going on here. I'm running node v22.11.0 and npm 10.9.0, I've ran
npm install
and then npm watch
. Many thanks!GitHub
examples/examples/with-javascript at main · sapphiredev/examples
Various examples of setting up your bot with the Sapphire Framework - sapphiredev/examples
10 Replies
The second is because you need to install a build toolchain, see https://github.com/nodejs/node-gyp#on-windows
The first... is because the code wasn't updated to Sapphire Plugin v7. If you don't need REST api plugin, just delete those files for now. If you do, then refer to the breaking changes, also we'd very much appreciate a PR ❤️
https://github.com/sapphiredev/plugins/blob/main/packages/api/CHANGELOG.md#sapphireplugin-api700---2024-11-02
GitHub
GitHub - nodejs/node-gyp: Node.js native addon build tool
Node.js native addon build tool. Contribute to nodejs/node-gyp development by creating an account on GitHub.
Thanks for the quick response! I'm guessing the docs need updating too with the new example code for 7.00? Unless the docs are specifically designed for an older version? https://www.sapphirejs.dev/docs/Guide/plugins/API/adding-routes
I'll try my best to workout how to fix it, unfortunately I'm very new to Node and Sapphire so might take some time, will try and do a PR 😅
Sapphire Framework
How to add routes | Sapphire
First we create a new folder called routes in the src directory. And make a new file hello-world
Oh, nevermind - that was pleasantly simple!
Changed it to this, which worked without issue. Is that the correct syntax to use? If so, I can open up a PR for both the examples and documentation 🙂 @Boomeravna
the docs are also still outdated yes
and there are many example files of how it should be here: https://github.com/skyra-project/skyra/tree/main/src/routes (TS though, but it comes down to mostly the same)
the new design is very much inspired by Nuxt which in turn draws some inspiration from Next and other file-based routing libraries so it should be very intuitive
Okay right, aye, I copied it from there and just removed the type annotations
yeah and the way it's exported if you're using CJS ofc
for the docs (https://github.com/sapphiredev/website) the input is TS only and it gets converted to JS-ESM and JS-CJS programatically
GitHub
GitHub - sapphiredev/website: Documentation for Sapphire Project
Documentation for Sapphire Project. Contribute to sapphiredev/website development by creating an account on GitHub.
Oh got you, that's clever
What's CJS?
CommonJS. For example the
module.exports
stuffAhh okay awesome