fastify / fastify/fastify-autoload
Cannot detect `@swc-node/register` loaded by `fastify-cli` with the `-r` option
- Dominant language
- JavaScript
- Stars
- 373
- Forks
- 77
- PR merge metrics
- No merged PRs in 30d
Description
### 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
4.28.1
### Plugin version
5.10.0
### Node.js version
20.x
### Operating system
Windows
### Operating system version (i.e. 20.04, 11.3, 10)
10
### Description
I'm using `fastify start -r @swc-node/register app.ts` to start my app written in TypeScript.
However, this plugin cannot detect `@swc-node/register` loaded by `fastify-cli` and the following error is thrown:
```console
Error: @fastify/autoload cannot import plugin at '~/fastify-app/plugins/sensible.ts'. To fix this error compile TypeScript to JavaScript or use
'ts-node' to run your app.
```
**Related PR:**
PR https://github.com/fastify/fastify-autoload/pull/191 fixed the case with `node -r @swc-node/register` but not with `fastify start -r @swc-node/register`.
**Current workaround:**
I have to manually set the `FASTIFY_AUTOLOAD_TYPESCRIPT` environment variable.
**Additional information:**
The current `checkPreloadModules()` util checks the `process._preload_modules` array, but it's empty when the package is required with `fastify-cli`.
### Link to code that reproduces the bug
https://github.com/zetaraku/fastify-app
### Expected Behavior
The plugin should be able to detect the `@swc-node/register` package loaded by `fastify start -r @swc-node/register`.
Contributor guide
Assessment
This issue has not been assessed yet.