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

add experimental-strip-types in app-ts-esm #798

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

SimoneDevkt
Copy link
Contributor

@SimoneDevkt SimoneDevkt commented Mar 6, 2025

I modified the app-ts-esm template by inserting the indicated tsconfig
https://nodejs.org/en/learn/typescript/run-natively#running-typescript-code-with-nodejs and erasableSyntaxOnly.
This way the dev script can directly launch the ts file with --experimental-strip-types

Checklist

@@ -162,6 +162,7 @@ function cli (args) {

template.devDependencies.c8 = cliPkg.devDependencies.c8
template.scripts.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'
template.scripts.dev = 'NODE_OPTIONS="--experimental-strip-types" FASTIFY_AUTOLOAD_TYPESCRIPT=1 fastify start -l info src/app.ts'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that we should introduce the --experimental-strip-types.
That flag is available from node 22.6, but fastify still support also node 20.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is coming to node 20 soon

@mcollina mcollina added the semver-major Issue or PR that should land as semver major label Mar 8, 2025
@mcollina
Copy link
Member

mcollina commented Mar 8, 2025

Once strip types ships in Node v20, I'd recommend shipping a new version of this as a semver-major.

@mcollina
Copy link
Member

mcollina commented Mar 8, 2025

Why is FASTIFY_AUTOLOAD_TYPESCRIPT=1 needed?

@SimoneDevkt
Copy link
Contributor Author

SimoneDevkt commented Mar 8, 2025

Why is FASTIFY_AUTOLOAD_TYPESCRIPT=1 needed?

I tried to run it without this flag, but I got an error. I don't know why

Error: @fastify/autoload cannot import plugin at '***\fastify-cli\test1\src\plugins\sensible.ts'. To fix this error compile TypeScript to JavaScript or use 'ts-node' to run your app.
    at handleTypeScriptSupport (***\fastify-cli\node_modules\@fastify\autoload\lib\find-plugins.js:152:11)
    at processFile (***\fastify-cli\node_modules\@fastify\autoload\lib\find-plugins.js:124:3)
    at processDirContents (***\fastify-cli\node_modules\@fastify\autoload\lib\find-plugins.js:101:7)
    at buildTree (***\fastify-cli\node_modules\@fastify\autoload\lib\find-plugins.js:41:9)
    at async findPlugins (***\fastify-cli\node_modules\@fastify\autoload\lib\find-plugins.js:14:3)
    at async autoload (***\fastify-cli\node_modules\@fastify\autoload\index.js:20:22)

https://github.com/fastify/fastify-autoload?tab=readme-ov-file#override-typescript-detection-using-an-environment-variable

@mcollina
Copy link
Member

mcollina commented Mar 8, 2025

fastify/fastify-autoload#442 < I think fastify-autoload would need some fixing. I think we can access process.features to detect if there is the support instead of relying on the version number.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver-major Issue or PR that should land as semver major
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants