I'm trying to set up tsx (typescript-execute) in my project, my package.json is as follows:
{
"name": "bb-tcg-backend",
"version": "1.0.0",
"description": "",
"main": "index.js",
"type": "module",
"scripts": {
"start": "node index.js",
"dev": "npx tsx watch ./index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"prisma": {
"seed": "node prisma/seed.js"
},
"devDependencies": {
"nodemon": "^3.1.7",
"prisma": "^6.2.1"
},
"dependencies": {
"@prisma/client": "^6.2.1",
"@types/express": "^5.0.0",
"@types/node": "^22.10.7",
"express": "^4.21.2",
"express-openapi": "^12.1.3",
"openapi-request-validator": "^12.1.3",
"tsx": "^4.19.2",
"typescript": "^5.7.3"
}
}
and my tsconfig.json:
{
"compilerOptions": {
"moduleDetection": "force",
"module": "ES2022",
"moduleResolution": "node",
"target": "ES2022",
"resolveJsonModule": true,
"allowJs": true,
"esModuleInterop": true,
"isolatedModules": true
}
}
When I do npm run dev tsx fails to import the openapi-request-validator package. It imports its index.js instead of the correct index.d.ts which is set up differently and as a result my code breaks. I cant figure out why it cant find the correct file. What could be the problem?
EDIT: tsc can find it without issue
======== Module name 'openapi-request-validator' was successfully resolved to '/home/martinkupa/Documents/coding/intro-camejo/tp2/back/node_modules/openapi-request-validator/dist/index.d.ts' with Package ID 'openapi-request-validator/dist/[email protected]'. ========
EDIT 2: For SEO purposes, the problem when running under the old tsconfig.json was TypeError: OpenAPIRequestValidator is not a constructor.