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

Not able to have top-level await in a ts ESM file? #316

Open
2 tasks done
stauersbol opened this issue Jun 28, 2023 · 3 comments
Open
2 tasks done

Not able to have top-level await in a ts ESM file? #316

stauersbol opened this issue Jun 28, 2023 · 3 comments

Comments

@stauersbol
Copy link

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.18.0

Plugin version

5.7.1

Node.js version

18.16.0

Operating system

Linux

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

Arch Linux x86_64 (kernel: 6.3.9-arch1-1)

Description

The "bug" is that, when I'm trying to auto load my routes from my routes folder, it appears that the plugin is not happy with me using top level await in my file.

But I don't get how that is something that the plugin should care much about?

As stated above, I'm trying to load routes from a 'routes' folder. This is because I didn't find much documentation on doing the registering of the routes via something like how Express does it with app.use('/login', loginRoutes).

I'm using tsx to run the app/server. Since I'm using TypeScript for it.

Steps to Reproduce

This will be pseudo code just to show the example:

import { TwitterAPI } from 'twitter-api-v2'

/// Create a Twitter client...

const user = await twitterClient.v2.me();

This is a simple way to mimic it, maybe there is a better way to reproduce it with just importing a simple function that returns a Promise with a type.

It should then give something like this(maybe only with one error in the error array, this is just using what I got):

  errors: [
    {
      detail: undefined,
      id: '',
      location: [Object],
      notes: [],
      pluginName: '',
      text: 'Top-level await is currently not supported with the "cjs" output format'
    },
    {
      detail: undefined,
      id: '',
      location: [Object],
      notes: [],
      pluginName: '',
      text: 'Top-level await is currently not supported with the "cjs" output format'
    }
  ],

Expected Behavior

I expected it to load the routes and not complain about the file trying to be a .cjs.

@stauersbol
Copy link
Author

UPDATE:

I have found a way to manually load the endpoints.
But I would still love to use this library.

@Eomm
Copy link
Member

Eomm commented Jul 19, 2023

Could you add a Minimal, Reproducible Example?

Without it, we are unable to help you.

@stauersbol
Copy link
Author

I will try to create a example of it.
Will provide it sometime tomorrow, since I'm busy with some things today.

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