Skip to content

Plugin must be a function or a promise. TypeScript project. #169

Closed
@wesbragagt

Description

@wesbragagt

Prerequisites

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

Fastify version

3.19.1

Plugin version

6.0.0

Node.js version

15

Operating system

Linux

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

Ubuntu 20.04

Description

I followed the documentation steps for the fastify-cli and fastify-http-proxy in order to implement the plugin and I keep getting the same error. Error: plugin must be a function or a promise.

Steps to Reproduce

  • Start a Fastify project using fastify generate project --lang=ts
  • cd project && npm install
  • paste the following code under app.ts
import { join } from 'path'
import AutoLoad, { AutoloadPluginOptions } from 'fastify-autoload'
import { FastifyPluginAsync } from 'fastify'
import fastifyHttpProxy from 'fastify-http-proxy'

// look into implementing this package https://github.com/fastify/fastify-http-proxy

export type AppOptions = {
    // Place your custom options for app below here.
} & Partial<AutoloadPluginOptions>

const app: FastifyPluginAsync<AppOptions> = async (
    fastify,
    opts
): Promise<void> => {
    // Place here your custom code!
    fastify.register(fastifyHttpProxy, {
        upstream: 'https://jsonplaceholder.typicode.com/todos',
        prefix: '/todos'
    })
    // Do not touch the following lines

    // This loads all plugins defined in plugins
    // those should be support plugins that are reused
    // through your application
    void fastify.register(AutoLoad, {
        dir: join(__dirname, 'plugins'),
        options: opts
    })

    // This loads all plugins defined in routes
    // define your routes in one of these
    void fastify.register(AutoLoad, {
        dir: join(__dirname, 'routes'),
        options: opts
    })
}

export default app
export { app }
  • npm run dev

Expected Behavior

You should get an error in the terminal saying "Error: plugin must be a function or a promise"

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions