I converted the JavaScript code to TypeScript and encountered an issue:
The module has no default export
I tried importing using curly braces and exporting with module.exports, but neither solution worked.
contactController.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!"
});
};
api-route.ts
import contactController from "./contactController";
In the api-routes.ts file, when attempting to import the contactController module, I received the error:
The module has no default export
How can I resolve this import error? I also tried using "import {contactController} from "./contactController" without success.