TypeScript Support
khill-fbmc opened this issue ยท 11 comments
๐๐ป Hello,
I'm DrummerOfFenrir from reddit, here doing what I said. I installed the package to see whats what and my first hiccup is no TypeScript types ๐ข
I made this
to eliminate those errors
so I will continue on.
I'm using Next.JS and trying this guide to get at the Next handler and use Express instead to add Pythagora
Hey man, thanks for catching that. Yes, we're actually working on a support for Typescript at the moment - it should be out very soon. Btw, that's awesome that you were able to find your way through. How does it work? Also, what db are you using?
I ran into another snag while trying to get it working. Here's more of my stack...
- NextJS + tRPC for backend comms.
- No DB at the moment, but I did setup FaunaDB because I am also...
- Using Next-Auth and eventually I might put the sessions in the DB
Now I believe my error came from using the next-auth middleware because when I try to start the custom server for Next, this streams in the console.
Here is my server file
import express, { Request, Response } from "express";
import next from "next";
import nextConfig from "./next.config";
const NODE_ENV = process.env.NODE_ENV ?? "development";
const port = 3000;
const hostname = "localhost";
const dev = NODE_ENV !== "production";
// when using middleware `hostname` and `port` must be provided below
const app = next({ dev, hostname, port, customServer: true, conf: nextConfig });
const handle = app.getRequestHandler();
(async () => {
try {
await app.prepare();
const server = express();
if (global.Pythagora) global.Pythagora.setApp(server);
server.all("*", (req: Request, res: Response) => {
return handle(req, res);
});
server.listen(port, (err?: any) => {
if (err) throw err;
console.log(`> Ready on localhost:${port}`);
console.log(`>> Environment: ${NODE_ENV}`);
});
} catch (e) {
console.error(e);
process.exit(1);
}
})();
Hmm, yes, that might be the problem. The next auth doesn't get captured. Although, that should fail while running tests and not while capturing. Were you able to run your app with Pythagora at all?
Btw, we just released the new version 0.0.28 in which express middlewares should work regardless of how is it called and we removed that one line of code (if (global.Pythagora) global.Pythagora.setApp(server);
) so now, you can literally just run npx pythagora --initScript ./your/server.js
.
I might have been doing it incorrectly...
I was just running the server file with node
not the Pythagora CLI tool ๐ฌ I thought all your sorcery somehow would pick it up?
On first attempt now, I think I have an issue with the server file trying to load the next.config.js
Note: I did upgrade to 0.0.28
first and remove the line you said
My new server file that I made a regular mjs
instead of ts
for now
import express from "express";
import next from "next";
import path from "path";
import { fileURLToPath } from "url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
(async () => {
const nextConfig = await import("file://" + __dirname + "/next.config.js");
const NODE_ENV = process.env.NODE_ENV ?? "development";
const port = 3000;
const hostname = "localhost";
const dev = NODE_ENV !== "production";
// when using middleware `hostname` and `port` must be provided below
const app = next({ dev, hostname, port, customServer: true, conf: nextConfig });
const handle = app.getRequestHandler();
try {
await app.prepare();
const server = express();
server.all("*", (req, res) => {
return handle(req, res);
});
server.listen(port, err => {
if (err) throw err;
console.log(`> Ready on localhost:${port}`);
console.log(`>> Environment: ${NODE_ENV}`);
});
} catch (e) {
console.error(e);
process.exit(1);
}
})();
Hey, I'm so sorry for the late response. We're planning to devote time to debugging Typescript so wanted to get back to you then but we just haven't gotten to it yet (it's only 2 of us). Btw, we just released support for native Mongodb and we're aiming to launch on product hunt by the end of the month so my hope is to get into debugging ts then.
I bounce around with what I am doing, so don't worry. I don't get blocked.
I am more an intrigued beta tester?
Awesome, I'll let you know once we debug typescript
hey @khill-fbmc ! Thanks for trying Pythagora and putting time in testing it.
There is a new version (0.0.36) we released today and it should work with typescript. We tried it on some simple repository and it worked. If you find time you can try it out and let us know how it went.
Have in mind some things changed so you might have to check Readme again on how to use commands ๐
Hi @khill-fbmc , I'm closing this issue since Typescript should be working but let us know if you need any other help.