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

[Help] Build fails with ESM project using TypeScript, Express, and TSOA #1227

Open
edwinhern opened this issue Oct 3, 2024 · 0 comments
Open

Comments

@edwinhern
Copy link

edwinhern commented Oct 3, 2024

Description

I'm trying to build an Express TypeScript project using tsup, but I'm encountering issues with the build process. The project uses ESM modules, Express, and TSOA for API generation.

Reproduction

  1. Clone the repository: https://github.com/edwinhern/express-typescript-2024.git
  2. Switch branch using git checkout feat08.24-tsoa
  3. Install dependencies: npm ci
  4. Run the build command: npm run build
  5. Run the start command npm run start

Current Behavior

The build process works, and when the application starts, it runs for a bit and stops with:

{"level":50,"time":1727985400631,"pid":63008,"hostname":"mbp.lan","name":"server start","msg":"Error during TSOA generation:"}

Expected Behavior

The project should build successfully, generating the necessary files in the dist directory, and the application should start without errors.

Environment

  • Node.js version: 22.9.0
  • npm version: 10.8.3
  • tsup version: 8.0.2
  • TypeScript version: 5.4.4
  • Operating System: MacOS

Configuration Files

tsconfig.json

{
  "compilerOptions": {
    /* Basic Options */
    "incremental": true,
    "target": "ESNext",
    "module": "ES2022",
    "outDir": "dist",

    /* 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,
    "resolveJsonModule": true,

    /* Experimental Options */
    "experimentalDecorators": true,

    /* Advanced Options */
    "types": ["vitest/globals"],
    "forceConsistentCasingInFileNames": true,
    "importsNotUsedAsValues": "remove",
    "paths": {
      "@/*": ["src/*"]
    }
  },
  "include": ["src/**/*"],
  "exclude": ["node_modules"]
}

package.json

{
  "name": "express-typescript-boilerplate",
  "version": "1.0.14",
  "description": "An Express boilerplate backend",
  "author": "Edwin Hernandez",
  "repository": "edwinhern/express-typescript-2024",
  "license": "MIT",
  "main": "src/index.ts",
  "private": true,
  "type": "module",
  "scripts": {
    "dev": "tsx watch --ignore 'src/api/generated/**' --clear-screen=false src/index.ts | pino-pretty",
    "build-api": "tsx src/common/utils/tsoa-generator.ts",
    "build": "tsoa spec-and-routes && tsup",
    "start": "node dist/index.js",
    "lint": "biome check src/",
    "lint:fix": "biome check src/ --fix",
    "format": "biome format src/",
    "test": "vitest run",
    "prepare": "husky"
  },
  "dependencies": {
    "cors": "^2.8.5",
    "dotenv": "^16.4.5",
    "envalid": "^8.0.0",
    "express": "^4.19.2",
    "express-rate-limit": "^7.2.0",
    "helmet": "^8.0.0",
    "http-status-codes": "^2.3.0",
    "pino": "^9.4.0",
    "pino-http": "^10.0.0",
    "swagger-ui-express": "^5.0.0",
    "tsoa": "^6.4.0"
  },
  "devDependencies": {
    "@biomejs/biome": "1.9.3",
    "@types/cors": "^2.8.17",
    "@types/express": "^4.17.21",
    "@types/supertest": "^6.0.2",
    "@types/swagger-ui-express": "^4.1.6",
    "husky": "^9.0.11",
    "lint-staged": "^15.2.2",
    "pino-pretty": "^11.0.0",
    "supertest": "^7.0.0",
    "tsup": "^8.0.2",
    "tsx": "^4.7.2",
    "typescript": "^5.4.4",
    "vite-tsconfig-paths": "^5.0.0",
    "vitest": "^2.0.0"
  },
  "lint-staged": {
    "*.{js,ts,cjs,mjs,d.cts,d.mts,json,jsonc}": ["biome check --apply --no-errors-on-unmatched"]
  },
  "tsup": {
    "entry": ["src", "!src/**/__tests__/**", "!src/**/*.test.*"],
    "sourcemap": false,
    "clean": true,
    "minify": true,
    "format": ["esm"],
    "skipNodeModulesBundle": true
  }
}

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • We receive the funding once the issue is completed & confirmed by you.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar
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