Deno express typescript is not working
Hi, I am trying to use deno with express and ts as this https://docs.deno.com/runtime/tutorials/how_to_with_npm/express/ example but getting any on express() result and also on middleware variables such as req, res.
any ideas?
deno version 1.44.4
the code
// @deno-types="npm:@types/express@4.17.15"
import express, { Request, Response } from "npm:express@4.18.2";
const app = express();
app.get("/", (req: Request, res: Response) => {
res.send("Welcome to the Dinosaur API!");
});
app.listen(8000);
6 Replies
also this
It seems like you're following the example from the documentation correctly, but you're encountering issues with the types for
express
. The any
type on express()
and the middleware variables like req
and res
suggests that the type definitions are not being applied as expected.
Here are a few steps you can take to troubleshoot this issue:
1. Ensure Correct Type Definitions: Make sure that the version of the type definitions (@types/express
) matches the version of express
you are importing. Mismatches between versions can sometimes lead to type errors.
2. Check Deno's Cache: Deno caches modules and type definitions. If there was an issue when fetching the types, it might have been cached incorrectly. You can refresh Deno's cache with the following command:
3. Permissions: Ensure that you are providing the necessary permissions when running your Deno script. For networking, you will need the --allow-net
flag.
4. Deno Version: Although you are using Deno version 1.44.4, make sure that it is up to date with the latest release that supports npm specifiers, as there might have been fixes or improvements related to npm support.
5. Type Checking: If you are running the script without type checking (using deno run --no-check
), try running it with type checking enabled to see if there are any type-related errors that need to be addressed.
6. Import Map: If you are using an import map, ensure that it is correctly configured to map the npm specifiers to the right URLs.
7. Deno Unstable Features: Since npm support in Deno is experimental, you might need to run Deno with the --unstable
flag to enable these features.
If you've tried these steps and are still facingissues, it might be helpful to look for any error messages that Deno is providing and use those to further diagnose the problem. If the issue persists, consider reaching out to the Deno community or checking if there are any open issues on the Deno GitHub repository that might be related to your problem. 🦕
Helpful Links:
Import modules from npm - Deno by Example
Import modules from npm - Deno by Example
node:
specifiers
Migrating from Node.js to Deno | Deno Docs
Build a REST API with Express, TypeScript, and Deno
Deno 1.25 Release Notes
Build Apps in Deno with Frameworks such as React, Vue, Express, and more.
Configuring TypeScript in Deno
How to use Express with DenoHi Tal, probably deno is not downloading the types from npm, if you wish to use express try use this endpoint instead:
https://esm.sh/express@4.19.2
While I'm here I highly suggest you, if possible to give a try to Hono: https://hono.dev.
It's very similar, but faster and a little bit more ergonomic in my opinion.
There seems to be a version mist match from express and types?
@fro.profesional dunno, trying to understand if anyone else experienced this