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

SWC Compatibility #2806

Closed
1 task done
brotsky opened this issue May 3, 2023 · 8 comments
Closed
1 task done

SWC Compatibility #2806

brotsky opened this issue May 3, 2023 · 8 comments
Labels

Comments

@brotsky
Copy link

brotsky commented May 3, 2023

Is there an existing issue that is already proposing this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe it

SWC works for NestJS but not NestJS/GraphQL.

It gives errors because SWC doesn't handle decorators such as @InputObject() and @typeobject().

Errors look like this:

 GraphQLError: Input Object type ExampleInput must define one or more fields.
        at SchemaValidationContext.reportError (/my/path/api/node_modules/graphql/type/validate.js:73:7)

The problem is that _GRAPHQL_METADATA_FACTORY() is not in the compiled JS.

You could reproduce this by running the standard next build script that uses tsc and looking at an input type that uses @InputObject(). Then running the swc build script (something like: npx swc src -d dist/src) and comparing the results. You will notice the _GRAPHQL_METADATA_FACTORY() is missing since it is created with the decorator.

Describe the solution you'd like

Ultimately, I just want it to work even if its a work around.

Teachability, documentation, adoption, migration strategy

No response

What is the motivation / use case for changing the behavior?

SWC is WAY faster than TSC, like 20x faster.

@brotsky brotsky added the feature label May 3, 2023
@srmagura
Copy link

srmagura commented May 3, 2023

Can you post your .swcrc?

Are decorators enabled in the jsc.parser options? https://swc.rs/docs/configuration/compilation#typescript

@srmagura
Copy link

srmagura commented May 3, 2023

Here's the swc config from the vite-plugin-node library, which works for me:

module: {
      type: 'es6',
    },
    jsc: {
      target: 'es2019',
      parser: {
        syntax: 'typescript',
        decorators: true,
      },
      transform: {
        legacyDecorator: true,
        decoratorMetadata: true,
      },
    },

@brotsky
Copy link
Author

brotsky commented May 4, 2023

Can you post your .swcrc?

Are decorators enabled in the jsc.parser options? https://swc.rs/docs/configuration/compilation#typescript

{
  "$schema": "https://json.schemastore.org/swcrc",
  "sourceMaps": "inline",
  "module": {
    "type": "commonjs",
    "strict": true
  },
  "exclude": [".*\\.js$", ".*\\.map$"],
  "jsc": {
    "target": "es2017",
    "parser": {
      "syntax": "typescript",
      "tsx": false,
      "decorators": true,
      "dynamicImport": false
    },
    "transform": {
      "legacyDecorator": true,
      "decoratorMetadata": true
    },
    "keepClassNames": true,
    "baseUrl": "./",
    "externalHelpers": true,
    "loose": false
  },
  "minify": false
}

@brotsky
Copy link
Author

brotsky commented May 4, 2023

Here's the swc config from the vite-plugin-node library, which works for me:


module: {

      type: 'es6',

    },

    jsc: {

      target: 'es2019',

      parser: {

        syntax: 'typescript',

        decorators: true,

      },

      transform: {

        legacyDecorator: true,

        decoratorMetadata: true,

      },

    },

Are you using Vite with NestJS? If so, is it a lot better? Do you think it will help make SWC work?

@srmagura
Copy link

srmagura commented May 8, 2023

I am using Vite with NestJS, through vite-plugin-node. There are a number of issues (mainly, no support for WebSockets), but it does work...

@brotsky
Copy link
Author

brotsky commented May 8, 2023

I am using Vite with NestJS, through vite-plugin-node. There are a number of issues (mainly, no support for WebSockets), but it does work...

Ah, that might be a dealbreaker. We are using GraphQL Subscriptions.

@srmagura
Copy link

srmagura commented May 9, 2023

See this comment for the solution I am currently using. It is working well.

@kamilmysliwiec
Copy link
Member

CLI plugins don't work with SWC, as stated in the docs.

@nestjs nestjs locked and limited conversation to collaborators May 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants