import http from 'http';
http.createServer((req, res) => {
res.end('Hello World');
}).listen(3000, () => console.log('Port is running on 3000'));
Run Code Online (Sandbox Code Playgroud)
我正在使用 @types/node 但它显示错误 HTTP 模块没有默认导出。
我已将 JavaScript 代码转换为 Typescript 并收到错误
模块没有默认导出
我曾尝试使用花括号导入并使用 module.exports 导出,但它们都不起作用。
联系人控制器.ts
const contacts: String[] = [];
// Handle index actions
exports.index = (req: any, res: any) => {
res.json({
data: contacts,
message: "Contacts retrieved successfully",
status: "success"
});
};
// Handle create contact actions
exports.new = (req: any, res: any) => {
// save the contact and check for errors
contacts.push("Pyramids");
res.json({
data: contact,
message: "New contact created!"
});
};
Run Code Online (Sandbox Code Playgroud)
api-route.ts
import contactController from "./contactController";
Run Code Online (Sandbox Code Playgroud)
在 api-routes.ts 中,当我尝试导入 contactController 模块时,它抛出错误
模块没有默认导出 …