fastify-cli icon indicating copy to clipboard operation
fastify-cli copied to clipboard

Generated Fastify ESM/TS app has broken `npm test` command (FASTIFY_AUTOLOAD_TYPESCRIPT)

Open Ragzouken opened this issue 5 months ago • 2 comments

Prerequisites

  • [x] I have written a descriptive issue title
  • [x] I have searched existing issues to ensure the bug has not already been reported

Fastify version

7.4.0

Plugin version

No response

Node.js version

24.4.0

Operating system

Windows

Operating system version (i.e. 20.04, 11.3, 10)

11

Description

Setup

fastify generate fastify-test --lang=ts --esm
cd fastify-test
npm install

Attempt

npm test

Outcome

> [email protected] test
> npm run build:ts && tsc -p test/tsconfig.json && FASTIFY_AUTOLOAD_TYPESCRIPT=1 node --test --experimental-test-coverage --loader ts-node/esm test/**/*.ts


> [email protected] build:ts
> tsc

'FASTIFY_AUTOLOAD_TYPESCRIPT' is not recognized as an internal or external command, 
operable program or batch file.

Link to code that reproduces the bug

see above

Expected Behavior

npm test should successfully run as generated.

Ragzouken avatar Jul 19 '25 14:07 Ragzouken

This error occurs because you're running a command with Linux/macOS syntax in the Windows Command Prompt (cmd).

The best and most common way to fix this is to use the cross-env library and update your test script by prefixing the environment variable with cross-env, like this:

cross-env FASTIFY_AUTOLOAD_TYPESCRIPT=1

chutientrong avatar Aug 01 '25 04:08 chutientrong

Hi @Ragzouken ✨, I reproduced this on Windows and confirmed the FASTIFY_AUTOLOAD_TYPESCRIPT env var fails in cmd. I tested with cross-env and it works cross-platform (Windows/Linux). Would you like me to open a PR updating the generated template’s test script to use cross-env? – Riya 🌷

riyap03 avatar Aug 20 '25 17:08 riyap03