-
-
Notifications
You must be signed in to change notification settings - Fork 68
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
Node 20 auto-loader not able to transpile TS to JS when using ts-node/esm #309
Comments
Moved to the autoload module. |
I would just hold this issue and only fix it when |
The APIs for loaders changed in v20 and it broke ts-node, mostly due to nodejs/node#47880. Once the dust settle and there is an API for us to use, we'll need to make adaptation here. |
Hi guys! I recently got bit by this, do we have any updates? |
Loaders are mostly stable now, so A PR would be highly welcomed, otherwise this will take a bit. |
not saying that I can do it, but where in the code should I take a look to know about how autoload deal with the loader flag? |
I debugged it and it seems, that clone the repo, open in vscode, install deps, set break point in node_modules/@fastifa/autoload/index.js in line 8. run |
Possibly related to |
thank you for the very informative tips on how to test it @Uzlopak. was testing with node 20.6.0 and the problem happens with tsx too! I guess is happening with all ts-loaders |
But you could do it "manually" by setting e.g. the TS_NODE_DEV to a truthy value. "scripts": {
"test": "TS_NODE_DEV=1 node --loader=ts-node/esm --experimental-specifier-resolution=node --test health.test.ts"
}, Maybe we should add a environment variable, like FASTIFY_AUTOLOAD_TS to generally override it |
@Uzlopak 's tip work. In my case I'm using tsx.
|
Can we label this issue as |
I created a PR #327 It is basically the same as TS_NODE_DEV but with the doubt, that it should not result in some side effects or whatever, because we use our own ENV variable. |
the original issue is still unresolved |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
I am going to lock the issue for collaborator only. For example,
For CJS user,
For ESM user,
|
I got the request to review this lock and to potentially moderate by @rhettjay After talking with @climba03003 I agree that the reported issue by @rhettjay is a misconfiguration in tsconfig, which results in a transpiled code by tsc so that nodejs cant load the code properly. We can not fix this as it is a pure configuration problem.also i assume we can not detect such misconfigurations at runtime. I checked and we are lacking this information in our README. So, @rhettjay , if you want you could add a new section in our Readme, which describes the necessary configuration for fastify autoload to work with typescript. Regarding the lock of the issue in this case needs the consent of @climba03003 to lift it. Also the question is, if this is still an issue. Maybe documenting the limitation resolves this issue. Then we could close it for good. IMHO if you take care of the documentation, we could then reevaluate this issue. If there is still an issue we have to decide what we do with it. If we document properly, what @climba03003 wrote, than the issue which you reported will become out of scope. So maybe then @climba03003 will agree on an unlock. If sombody then reports similar problems we can redirect that person to the corresponding part of the documentation. If the issue gets heated again, we can lock it again. Summary: Personal Note: Unfortunately i cant give you a better answer but I think this is answering your request to everybodies satisfaction. Looking forward for your upcoming participation in OSS. :). Best Regards |
Please check the latest version I will close the issue, but open public comment for feedback. |
Prerequisites
Fastify version
4.10.0
Plugin version
No response
Node.js version
20.1.0
Operating system
macOS
Operating system version (i.e. 20.04, 11.3, 10)
13.3.1
Description
I think this is a Node issue, but only
@fastify/autoloader
is affected by it, so I am opening an issue with you good folks as well in case this is really a Fastify issue instead or if it is a Node issue but you are able to find a workaround!This piece of code works in Node 19 when using
node --loader=ts-node/esm
(the route files are in TypeScript) but not on Node 20.I have come up with a repro here: https://github.com/TomasHubelbauer/node-esm-loader-repro
Steps to Reproduce
Follow my repro repo: https://github.com/TomasHubelbauer/node-esm-loader-repro
Steps copied here for posterity.
Node 20:
nvm install 20
to install Node 20node --version
to ensure Node version (I get 20.1.0)npm install
to install dependenciesnpm run test
to run thehealth.test.ts
scriptNotice the test fails and Fastify's
autoload
is seemingly not aware of the--loader
option and attempts to loadroutes/health.ts
without TypeScript toJavaScript conversion via
ts-node/esm
.Node 19:
nvm install 19
to install Node 20node --version
to ensure Node version (I get 19.9.0)npm install
to install dependenciesnpm run test
to run thehealth.test.ts
scriptNotice the test passes and Fastify's
autoload
is inherit the--loader
optionand uses the
ts-node/esm
loader successfully to auto-loadroutes/health.ts
.Expected Behavior
Works the same way in both 19 and 20.
The text was updated successfully, but these errors were encountered: