fastify-cli: Typescript handling broken in 2.4

💥 Regression Report

#276 (2.4.0) screwed up our whole typescript dev workflow. We had it working perfectly fine (including watching) before with simply doing

ts-node ./node_modules/.bin/fastify start -w -l info -P -p 3001 src/index.ts

Nothing else was required to get it working, no code changes etc. (Imho this would also be an easier solution than all the code changes in #276)

In the new version fastify-cli now first errors with

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined
    at validateString (internal/validators.js:122:11)
    at resolve (path.js:980:7)
    at watchMain (/Users/tschinde/Documents/rg/tech-dept-app/api/node_modules/fastify-cli/lib/watch/tsc-watcher.js:50:24)

because we do not specify an outDir directly in the main typescript config, but rather in the some inherited config. Even after changing this and defining an outDir and rootDir the emitting of files is not working correctly. I have my source in src/ and the code emitted is going into lib/src/ but that is not where it should go, it should just go into lib/. So the app crashes because it cannot find files.

my tsconfig (with outDir and rootDir specified to fix above, with ts-node only rootDir: "./" was set which is also needed for the typescript tests) is:

{
    "include": [
      "src"
    ],
    "extends": "../tsconfig.json",
    "compilerOptions": {
      "outDir": "lib",
      "rootDir": "src"
    }
  }

../tsconfig.json is:

{
  "exclude": ["node_modules", "__tests__", "dist", "lib"],
  "compilerOptions": {
    "lib": ["es2019"],
    "target": "es2019",
    "module": "commonjs",
    "rootDir": ".",
    "outDir": "lib",
    "strict": true,
    "allowJs": false,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noImplicitReturns": true,
    "noImplicitAny": true,
    "noImplicitThis": true,
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "resolveJsonModule": true,
    "baseUrl": ".",
    "declaration": false,
    "sourceMap": false,
    "allowSyntheticDefaultImports": true,
    "moduleResolution": "node",
    "isolatedModules": true
  }
}

For now I reverted and will stay on latest 2.3.x

Last working version

Worked up to version: 2.3.x

Stopped working in version: 2.4.0

Your Environment

  • node version: 12
  • fastify version: 3.6.0
  • os: Mac
  • ts: 3.9.7

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 15 (13 by maintainers)

Most upvoted comments

I’ll ship a revert in the morning.