tsoa
tsoa copied to clipboard
Following Guide Produces Errors
Sorting
-
I'm submitting a ...
- [X] bug report
- [ ] feature request
- [ ] support request
-
I confirm that I
- [X] 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
- Follow the guide
- Run
yarn run tsoa routes
- 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": "[email protected]",
"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]