0

I am using hapi-router npm module. Can not use hapi-router with typescript.

await server.register(
    {
        plugin: HapiRouter,
        options: {
            routes: "./src/api/**/routes.ts",
        },
    },
    { routes: { prefix: "/api/v1" } }
);

My route.ts file looks like this

import controller from "./controller";
import validator from "./validator";
export default [{
    method: "GET",
    path: "/products/{id}",
    options: {
        tags: ["api", "Products"],
        description: "Get Product By ID",
        validate: validator.byId
    },
    handler: controller.byId
}]

It gives me an error: "Can not use import statement outside a module" Even when I use require statement it doesn't work.

  • are you importing anything outside the src? – Jamal Dec 07 '21 at 07:39
  • @Jamal I didn't import anything outside the src – Tanjir Antu Dec 07 '21 at 08:16
  • check this https://stackoverflow.com/questions/58384179/syntaxerror-cannot-use-import-statement-outside-a-module – Jamal Dec 07 '21 at 08:23
  • @Jamal This is not the solution. I have checked the answer you posted. Hapi router is not supported with typescript. The problem was in persing and requiring the route files which I found out later. May the guy who made the plugin needs to add typescript support. – Tanjir Antu Dec 07 '21 at 11:10

0 Answers0