GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — generate-swagger doesn't work with typescript code · Issue #608 · fastify/fastify-cli

generate-swagger doesn't work with typescript code #608

New issue
Copy link
New issue
Copy link
Open
Open
generate-swagger doesn't work with typescript code#608
Copy link

Description

@smaant
smaant
opened on Mar 27, 2023
Issue body actions

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

Plugin version

No response

Node.js version

v19.7.0

Operating system

macOS

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

Monterey (12.5.1)

Description

I'm trying to generate swagger using fastify-cli for a Typescript project and getting an error SyntaxError: Cannot use import statement outside a module.

Steps to Reproduce

  1. Create a new Fastify project from template:
$ fastify generate --lang=ts test-project
  1. Run npm install

  2. Add @fastify/swagger - npm install @fastify/swagger

  3. In the src/app.ts add:

+ import swagger from '@fastify/swagger';

// [skipped]

const app: FastifyPluginAsync<AppOptions> = async (
    fastify,
    opts
): Promise<void> => {
  // Place here your custom code!
+  fastify.register(swagger, {});

// [skipped remaining]
  1. Try generating swagger:
$ fastify generate-swagger src/app.ts
  1. Observe the error
import { join } from 'path';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at internalCompileFunction (node:internal/vm:73:18)
    at wrapSafe (node:internal/modules/cjs/loader:1195:20)
    at Module._compile (node:internal/modules/cjs/loader:1239:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1329:10)
    at Module.load (node:internal/modules/cjs/loader:1133:32)
    at Module._load (node:internal/modules/cjs/loader:972:12)
    at Module.require (node:internal/modules/cjs/loader:1157:19)
    at require (node:internal/modules/helpers:119:18)
    at requireServerPluginFromPath (/Users/anton/.nvm/versions/node/v19.7.0/lib/node_modules/fastify-cli/util.js:79:20)
    at async runFastify (/Users/anton/.nvm/versions/node/v19.7.0/lib/node_modules/fastify-cli/generate-swagger.js:60:12)

Expected Behavior

No response

Reacted by Bakhtiyar and jk2K

Activity

  1. mcollina commented on Mar 27, 2023

    @mcollina
    mcollina
    on Mar 27, 2023
    Member
    More actions

    Thanks for reporting! Would you like to send a Pull Request to address this issue? Remember to add unit tests.

    Reacted by Yazalde Filimone
  2. yazaldefilimone commented on May 1, 2023

    @yazaldefilimone
    yazaldefilimone
    on May 1, 2023
    Contributor
    More actions

    Thanks for reporting! Would you like to send a Pull Request to address this issue? Remember to add unit tests.

    I would like try it...

  3. mcollina commented on May 2, 2023

    @mcollina
    mcollina
    on May 2, 2023
    Member
    More actions

    Go for it!

  4. aehtatsirk commented on Jul 21, 2023

    @aehtatsirk
    aehtatsirk
    on Jul 21, 2023
    More actions

    any updates here?

    Reacted by Yazalde Filimone
  5. yazaldefilimone commented on Jul 21, 2023

    @yazaldefilimone
    yazaldefilimone
    on Jul 21, 2023
    Contributor
    More actions

    @mcollina
    @aehtatsirk
    @smaant
    I am very sorry for the delay, I ended up feeling discouraged and sad for not knowing how to do it at the time, but after receiving the email for this comment, I put my brain to work and solved this #641 I hope I helped

  6. segevfiner commented on Sep 10, 2023

    @segevfiner
    segevfiner
    on Sep 10, 2023
    Contributor
    More actions

    Personally. I just called generate-swagger with the compiled js file. Like how you use fastify start with the compiled JS file. fastify-cli itself has no native TypeScript support so needs a separate build step. It will need to integrate ts-node or preferably tsx, which has far less problems than ts-node for this, which is a separate feature IMHO.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.