Generated Fastify ESM/TS app has broken `npm test` command (FASTIFY_AUTOLOAD_TYPESCRIPT)
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.
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
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 🌷