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

How does it work with @fastify/autoload ? #7

Open
ianzone opened this issue May 31, 2022 · 6 comments
Open

How does it work with @fastify/autoload ? #7

ianzone opened this issue May 31, 2022 · 6 comments

Comments

@ianzone
Copy link

ianzone commented May 31, 2022

Very cool boilerplate, but I got lost when trying to add @fastify/autoload...

@ManUtopiK
Copy link
Owner

It works as usual, like described here https://github.com/fastify/fastify-autoload
You should use ESM syntax:

// src/app.ts
import autoLoad from '@fastify/autoload'
import { dirname, join } from 'path'
import { fileURLToPath } from 'url'

export default async (opts?: FastifyServerOptions) => {
  const fastify = Fastify(opts)

  fastify.register(autoLoad, {
    dir: join(__dirname, 'plugins')
  })

...

@ianzone
Copy link
Author

ianzone commented May 31, 2022

just found that the @fastify/autoload can not utilize the vite-plugin-node, it's reported here fastify/fastify-autoload#230

and here is my test result:

❯ npm run dev

[email protected] dev
vite

vite v2.9.9 dev server running at:

Local: http://localhost:3000/
Network: use --host to expose

ready in 270ms.

/home/ian/templates/fastify/node_modules/.pnpm/@fastify[email protected]/node_modules/@fastify/autoload/index.js:222
throw new Error(@fastify/autoload cannot import plugin at '${file}'. To fix this error compile TypeScript to JavaScript or use 'ts-node' to run your app.)
^

Error: @fastify/autoload cannot import plugin at '/home/ian/templates/fastify/src/routes/root.ts'. To fix this error compile TypeScript to JavaScript or use 'ts-node' to run your app.
at findPlugins (/home/ian/templates/fastify/node_modules/.pnpm/@fastify[email protected]/node_modules/@fastify/autoload/index.js:222:15)
at async autoload (/home/ian/templates/fastify/node_modules/.pnpm/@fastify[email protected]/node_modules/@fastify/autoload/index.js:30:22)

Node.js v18.2.0

@ManUtopiK
Copy link
Owner

Thanks for your feedback. I'll take a look...

@clabnet
Copy link

clabnet commented Nov 18, 2022

Also for me, same issue.

@tompahoward
Copy link

Similar issue in vitest that has a solution fastify/fastify-autoload#230 (comment)

I have no idea if there's a similar solution for vite-plugin-node

@ManUtopiK
Copy link
Owner

Thanks for the link. I will take a try...

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

4 participants