Skip to content
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

Following Guide Produces Errors #1683

Open
2 of 4 tasks
dustin-lennon opened this issue Sep 19, 2024 · 1 comment
Open
2 of 4 tasks

Following Guide Produces Errors #1683

dustin-lennon opened this issue Sep 19, 2024 · 1 comment

Comments

@dustin-lennon
Copy link

Sorting

  • I'm submitting a ...

    • bug report
    • feature request
    • support request
  • I confirm that I

    • used the search to make sure that a similar issue hasn't already been submit

Expected Behavior

Following the guide allowing for building with no errors to learn about TSOA.

Current Behavior

The following error occurs

❯ yarn run tsc --outDir build --experimentalDecorators
build/routes.ts:4:69 - error TS2307: Cannot find module '@tsoa/runtime' or its corresponding type declarations.

4 import { TsoaRoute, fetchMiddlewares, ExpressTemplateService } from '@tsoa/runtime';
                                                                      ~~~~~~~~~~~~~~~

build/routes.ts:7:91 - error TS2307: Cannot find module 'express' or its corresponding type declarations.

7 import type { Request as ExRequest, Response as ExResponse, RequestHandler, Router } from 'express';
                                                                                            ~~~~~~~~~

src/app.ts:2:43 - error TS2307: Cannot find module 'express' or its corresponding type declarations.

2 import express, { json, urlencoded } from "express";
                                            ~~~~~~~~~

src/server.ts:4:14 - error TS2580: Cannot find name 'process'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node`.

4 const port = process.env.PORT || 3000;
               ~~~~~~~

src/users/usersController.ts:11:8 - error TS2307: Cannot find module 'tsoa' or its corresponding type declarations.

11 } from "tsoa";
          ~~~~~~

src/users/usersController.ts:30:10 - error TS2339: Property 'setStatus' does not exist on type 'UsersController'.

30     this.setStatus(201); // set return status 201
            ~~~~~~~~~


Found 6 errors in 4 files.

Errors  Files
     2  build/routes.ts:4
     1  src/app.ts:2
     1  src/server.ts:4
     2  src/users/usersController.ts:11

Steps to Reproduce

  1. Follow the guide
  2. Run yarn run tsoa routes
  3. Run yarn run tsc --outDir build --experimentalDecorators

Context (Environment)

Version of the library: 6.4.0
Version of NodeJS: 22.2.0

tsconfig.json

{
  "compilerOptions": {
    /* Basic Options */
    "incremental": true,
    "target": "es6",
    "module": "commonjs",
    "outDir": "build",

    /* Strict Type-Checking Options */
    "strict": true,
    "noImplicitAny": true,
    "strictNullChecks": true,
    "strictFunctionTypes": true,
    "strictBindCallApply": true,
    "strictPropertyInitialization": true,
    "noImplicitThis": true,
    "alwaysStrict": true,

    /* Additional Checks */
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noImplicitReturns": true,
    "noFallthroughCasesInSwitch": true,

    /* Module Resolution Options */
    "moduleResolution": "node",
    "baseUrl": ".",
    "esModuleInterop": true,

    /* Experimental Options */
    "experimentalDecorators": true,
    // emitDecoratorMetadata is not needed by tsoa (unless you are using Custom Middlewares)

    /* Advanced Options */
    "forceConsistentCasingInFileNames": true
  }
}

package.json

{
  "name": "tsoa-project",
  "main": "build/src/server.js",
  "packageManager": "yarn@4.1.1",
  "dependencies": {
    "express": "^4.21.0",
    "tsoa": "^6.4.0"
  },
  "scripts": {
    "build": "tsoa spec-and-routes && tsc",
    "start": "node build/src/server.js"
  },
  "devDependencies": {
    "@types/express": "^4.17.21",
    "@types/node": "^22.5.5",
    "typescript": "^5.6.2"
  }
}

Errors showing in VSCode

// src/users/usersController.ts
import {
  Body,
  Controller,
  Get,
  Path,
  Post,
  Query,
  Route,
  SuccessResponse,
} from "tsoa";

Cannot find module 'tsoa' or its corresponding type declarations.

  @SuccessResponse("201", "Created") // Custom success response
  @Post()
  public async createUser(
    @Body() requestBody: UserCreationParams
  ): Promise<void> {
    this.setStatus(201); // set return status 201
    new UsersService().create(requestBody);
    return;
  }

Property 'setStatus' does not exist on type 'UsersController'.

  • Confirm you were using yarn not npm: [X]
Copy link

Hello there dustin-lennon 👋

Thank you for opening your very first issue in this project.

We will try to get back to you as soon as we can.👀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant