1

I'm using tsconfig-paths and tsoa in a project. I used tsconfig-paths following with document.

Please get code here.

I got error after running debug:

/home/tailt/.nvm/versions/node/v19.1.0/bin/node -r /home/tailt/Workspace/projects/private-projects/New Folder/test-tsconfig-paths-tsoa-bugs/node_modules/ts-node/register -r /home/tailt/Workspace/projects/private-projects/New Folder/test-tsconfig-paths-tsoa-bugs/node_modules/tsconfig-paths/register ./dist/index.js
/home/tailt/Workspace/projects/private-projects/New Folder/test-tsconfig-paths-tsoa-bugs/src/controllers/ping.controller.ts:9
  @Get("/")
      ^
node_modules/@cspotcode/source-map-support/source-map-support.js:590
TypeError: (0 , tsoa_1.Get) is not a function
    at Object.<anonymous> (/home/tailt/Workspace/projects/private-projects/New Folder/test-tsconfig-paths-tsoa-bugs/src/controllers/ping.controller.ts:9:7)
    at Module._compile (node:internal/modules/cjs/loader:1205:14)
    at Module.m._compile (/home/tailt/Workspace/projects/private-projects/New Folder/test-tsconfig-paths-tsoa-bugs/node_modules/ts-node/src/index.ts:1455:23)
    at Module._extensions..js (node:internal/modules/cjs/loader:1259:10)
    at Object.require.extensions.<computed> [as .ts] (/home/tailt/Workspace/projects/private-projects/New Folder/test-tsconfig-paths-tsoa-bugs/node_modules/ts-node/src/index.ts:1458:12)
    at Module.load (node:internal/modules/cjs/loader:1068:32)
    at Function.Module._load (node:internal/modules/cjs/loader:909:12)
    at Module.require (node:internal/modules/cjs/loader:1092:19)
    at require (node:internal/modules/cjs/helpers:103:18)
    at Object.<anonymous> (/home/tailt/Workspace/projects/private-projects/New Folder/test-tsconfig-paths-tsoa-bugs/src/routes/index.ts:2:1)
node_modules/@cspotcode/source-map-support/source-map-support.js:594
Process exited with code 1

If if don't use tsconfig-paths, it works.

How can I fix this error?

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
Tai Lu
  • 43
  • 7
  • For some reason, tsconfig-paths can't load tsoa. I added more lines in tsconfig.json: `paths: {"tsoa": ["node_modules/tsoa/dist"]`. It worked. – Tai Lu Feb 10 '23 at 05:29

1 Answers1

0

in case that somebody faces the same issue, but in jest test here how to fix it:

Add this to your jest.config file

moduleNameMapper: {
    // Jest is unable to find tsoa without this
    '@tsoa/runtime': '<rootDir>/node_modules/@tsoa/runtime/dist',
    tsoa: '<rootDir>/node_modules/tsoa/dist',
  },

My rootDir is ".", so take that in mind to adjust in case yours is diferent

UPDATE 29/06

After some research i figured out that the solution i described above is more a patch than a solution.

The real problem in my case was a wrong configuration that somebody put on our jest.config.js.

Ensure that your rootDir and modulePaths is correct

Pablo
  • 21
  • 3