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 support for .ts files when app is not run with ts-node. #264

Merged
merged 3 commits into from
Sep 1, 2022

Conversation

kylerush
Copy link
Contributor

@kylerush kylerush commented Aug 31, 2022

This branch adds support for .ts files when the application is not run with ts-node. The specific use case for this is mentioned in #230. Vitest does not run with ts-node (it uses es-build) to compile TypeScript. This creates a situation where some.ts files that AutoLoad tries to import fails because there is no Typescript transpiler.

This pull request resolves #230.

To make the tests fail

Replace lines 32-42 in test/commonjs/error.js with app3.register(require('./index-error/app')). This will cause the plugin to load ts-node from the Node modules and not throw an error to the user that they need to install ts-node.

Replace index.js with the current version of the file in the master branch. This will cause the test files in test/commonjs/ts-node.js to error because it cannot load .ts files without either being run with ts-node or the ts-node register that is added in this branch.

Notes

I did not modify any documentation as the error messages in index.js will still make sense. Happy to revise the documentation if requested.

Per request, I added vite and vitest as devDependencies and added some vitest tests so that we don't lose vitest support.

Also happy to make any changes needed to this. Thanks for reviewing!

Checklist

  • run npm run test and npm run benchmark
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message and code follows the [Developer's Certification of Origin]

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

Could you add some tests with vitest, so we make sure we do not regress in vitest support?

index.js Outdated Show resolved Hide resolved
index.js Outdated Show resolved Hide resolved
@kylerush
Copy link
Contributor Author

Yes, will work on adding some tests with vitest. Good idea.

@kylerush
Copy link
Contributor Author

kylerush commented Sep 1, 2022

@mcollina all set. added some tests with vitest.

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

lgtm

@bcomnes
Copy link

bcomnes commented Sep 1, 2022

This change is breaking my non-ts fastify servers #266

@ManUtopiK
Copy link

ManUtopiK commented Nov 10, 2022

It also not work with vite-node either with vite-plugin-node
with @fastify/autoload": "^5.4.1".
forceESM change nothing.
It always throw this error:

`@fastify/autoload cannot import plugin at '${file}'. To fix this error compile TypeScript to JavaScript or use 'ts-node' to run your app.`

@climba03003
Copy link
Member

climba03003 commented Nov 11, 2022

Please open your own issue with a proper reproducible example.
Different environment require differences fix.

@fastify fastify locked as resolved and limited conversation to collaborators Nov 11, 2022
@kylerush kylerush deleted the krush/ts-node branch November 18, 2022 21:23
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Typescript compiler error when running tests using Vitest
5 participants