0

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.

1 Answer 1

1

It seems that tsx doesnt yet support loading .d.ts files.

EDIT: It seems like this might be an issue with the package itself instead of my config. In any case, I managed to make it work both on tsc and tsx by removing all configuration related to ES6 modules from my tsconfig.json and changing the target to ES5

{
    "compilerOptions": {
        "moduleResolution": "node",
        "target": "ES5",
        "outDir": "dist/",
        "resolveJsonModule": true,
        "allowJs": true,
        "esModuleInterop": true,
        "isolatedModules": true,
    },
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.