import * as express from 'express';
import { Request, Response, Application } from 'express'; // <-- Error here
当我使用'Request'
、'Response'
和'Application'
时,出现了错误(Module has no imported member
)。
我发现在node_modules
中的/lib
子目录中有request.js
、response.js
和application.js
。根据错误跟踪,我猜测Express没有检查/lib
子目录。在使用import
时,如何强制/指导系统检查/lib
子目录?(或者这不是问题,而是完全不同的问题?)
我尝试过import { Request, Response, Application } from 'express/lib'
和import * as expressLib from 'express/lib'
,然后再使用import {Request, Response, Application } from expressLib
,但这两种方法都不起作用。
注意:因为Request
和Response
是Object类型,所以我假设它们应该保持大写?
import * as express from 'express';
// import * as expressLib from 'express/lib'
import { Request, Response, Application } from 'express';
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser');
import * as jwt from 'jsonwebtoken';
import * as fs from "fs";
const app: Application = express();
app.use(bodyParser.json());
app.route('api/login')
.post(loginRoute);
const RSA_PRIVATE_KEY = fs.readFileSync('/demos/private.key');
export function loginRoute(req: Request, res: Response) {
const email = req.body.email,
password = req.body.password;
if (validateEmailAndPassword()) {
const userId = findUserIdForEmail(email);
const jwtBearerToken = jwt.sign({}, RSA_PRIVATE_KEY, {
algorithm: 'RS256',
expiresIn: 120,
subject: userId
});
// res.cookie("SESSIONID", jwtBearerToken, {httpOnly: true, secure: true});
res.status(300).json({
idToken: jwtBearerToken,
expiresIn: ""
})
} else {
res.sendStatus(401);
}
}
import { Request, Response, Application } from 'express'
有效了。另外,我编辑了我的原始帖子,以提供更多关于为什么我认为这些应该是大写字母的细节。非常感谢您的查看。 - Crowdpleasr