Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Error message TS2339: Property 'use' does not exist on type 'Router'. #6030

Closed
xuetong6 opened this issue Oct 8, 2024 · 4 comments
Closed
Labels

Comments

@xuetong6
Copy link

xuetong6 commented Oct 8, 2024

"@types/express": "^5.0.0",
"express": "^4.21.0",

import { Router } from "express";
import cors from "cors";

export const handleCors = (router: Router) =>
router.use(cors({ credentials: true, origin: true }));

TS2339: Property 'use' does not exist on type 'Router'
Please help me see what the reason is

@593-ACD
Copy link

593-ACD commented Oct 8, 2024

Hey, are you trying to setup cors for the entire app or just a specific route ?

For the entire app it look like this:

import express from "express";
import cors from "cors";

const app = express();

app.use(cors({credentials:true,origin:true}));

@xuetong6
Copy link
Author

xuetong6 commented Oct 8, 2024

const router = express();
applyMiddleware(middleware, router);

My router was passed from another file

@NewEraCracker
Copy link

This issue will help you: #5987

You should pin the @types/express to ^4.17.21

@dev-gabriel-henrique
Copy link

dev-gabriel-henrique commented Nov 12, 2024

Try to use:
const router = Router()
export handleCors = router.use(cors({ credentials: true, origin: true}));

And verify if the @types of express is installed.

@IamLizu IamLizu converted this issue into discussion #6168 Nov 12, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
Projects
None yet
Development

No branches or pull requests

4 participants