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

Fastify autoload throwing errors about ts in projects that don't use ts #266

Closed
2 tasks done
bcomnes opened this issue Sep 1, 2022 · 4 comments
Closed
2 tasks done

Comments

@bcomnes
Copy link

bcomnes commented Sep 1, 2022

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Fastify version

4.x.x

Plugin version

5.3.0

Node.js version

18.x

Operating system

macOS

Operating system version (i.e. 20.04, 11.3, 10)

Linux and macOS 12.5.1

Description

It looks like #264 is breaking non-ts fastify projects.

What was previously working now gets the following error:

Error: @fastify/autoload cannot import plugin at '/Users/bret/Developer/breadcrum.net/plugins/accepts.js'. To fix this error compile TypeScript to JavaScript or use 'ts-node' to run your app.
    at findPlugins (/Users/bret/Developer/breadcrum.net/node_modules/@fastify/autoload/index.js:224:17)
    at async autoload (/Users/bret/Developer/breadcrum.net/node_modules/@fastify/autoload/index.js:28:22)

The accepts plugin mentinoned in the error is very simple and does not use TS

import fp from 'fastify-plugin'

/**
 * This plugins adds fastify-auth
 *
 * @see https://github.com/fastify/fastify-accepts
 */
export default fp(async function (fastify, opts) {
  fastify.register(import('@fastify/accepts'))
}, {
  name: 'accepts',
  dependencies: []
})

Steps to Reproduce

Try to load the above plugin on a ts free auto-load project set to esm module mode.

import fp from 'fastify-plugin'

/**
 * This plugins adds fastify-auth
 *
 * @see https://github.com/fastify/fastify-accepts
 */
export default fp(async function (fastify, opts) {
  fastify.register(import('@fastify/accepts'))
}, {
  name: 'accepts',
  dependencies: []
})

Here is a reproducible example generated from the fastify-cli and then converted to esm.

https://github.com/ballpit/fastify-autoload-bug

Downgrading fastify-autoload to 5.2.0 fixes the build.

Expected Behavior

That projects not using TS don't throw errors about ts.

@bcomnes
Copy link
Author

bcomnes commented Sep 1, 2022

I added a reproducible example generated from the fastify-cli:

https://github.com/ballpit/fastify-autoload-bug

@bcomnes
Copy link
Author

bcomnes commented Sep 1, 2022

Looks like if you simply generate a cjs scaffold that also breaks.

Error: @fastify/autoload cannot import plugin at '/Users/bret/Developer/scratch/common-fast0-bug/plugins/sensible.js'. To fix this error compile TypeScript to JavaScript or use 'ts-node' to run your app.
    at findPlugins (/Users/bret/Developer/scratch/common-fast0-bug/node_modules/@fastify/autoload/index.js:224:17)
    at async autoload (/Users/bret/Developer/scratch/common-fast0-bug/node_modules/@fastify/autoload/index.js:28:22)

@bcomnes bcomnes closed this as completed Sep 1, 2022
@bcomnes bcomnes reopened this Sep 1, 2022
@bcomnes
Copy link
Author

bcomnes commented Sep 1, 2022

@kylerush any ideas on how to fix?

@mcollina
Copy link
Member

mcollina commented Sep 1, 2022

I've just shipped v5.3.1 with a revert.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants