MichalLytek / type-graphql

Create GraphQL schema and resolvers with TypeScript, using classes and decorators!
https://typegraphql.com
MIT License
7.98k stars 674 forks source link

`registerEnumType` is not a named export after compilation #1598

Closed nemanjastanic closed 6 months ago

nemanjastanic commented 6 months ago

Describe the Bug I started having this issue after upgrading from 2.0.0-beta.2 to 2.0.0-beta.4. I can confirm this because it was fixed after downgrading to 2.0.0-beta.3.

I am using SWC to compile my project.

To Reproduce

import { registerEnumType } from "type-graphql";

export enum SendTo {
  Channel = "Channel",
  Contact = "Contact",
}

registerEnumType(SendTo, {
  name: "SendTo",
});

The following snippet will fail with these configurations.

.swcrc

{
  "$schema": "https://json.schemastore.org/swcrc",
  "isModule": true,
  "jsc": {
    "target": "esnext",
    "preserveAllComments": false,
    "experimental": { "keepImportAssertions": true },
    "parser": {
      "syntax": "typescript",
      "decorators": true,
      "dynamicImport": true,
      "dts": true
    },
    "baseUrl": ".",
    "paths": {}
  }
}

tsconfig.json

{
  "extends": "@secret/tsconfig/base.json",
  "compilerOptions": {
    "baseUrl": ".",
    "rootDir": "./src",
    "outDir": "dist",
    "jsx": "preserve",
    "types": ["node", "reflect-metadata"],
    "paths": {}
  },
  "include": ["./src/**/*"],
  "exclude": ["dist", "node_modules"]
}

Expected Behavior The function is imported without any issues.

Logs Screenshot 2024-01-04 at 5 45 09 PM

Environment (please complete the following information):

MichalLytek commented 6 months ago

@carlocorradini Might this be related to ESM support?

carlocorradini commented 6 months ago

ESM code is using require instead of import: Screenshot_2024-01-05-14-50-46-14_40deb401b9ffe8e1df2f1cc5ba480b12.jpg

@MichalLytek How did you build the package? I'll try locally to check if this is due to an upgrade of a dependency

carlocorradini commented 6 months ago

@MichalLytek I confirm is the build process

MichalLytek commented 6 months ago

@carlocorradini image

carlocorradini commented 6 months ago

@MichalLytek I've tried downgrading to typescript v5.1.6 (same as alpha) and manually:

npx tsc --build ./tsconfig.esm.json

And it does not works. It looks like typescript is ignoring esm... WTF 😅 Any thoughts?

MichalLytek commented 6 months ago

It was working as we've published beta 3 via gh actions 😄

MichalLytek commented 6 months ago

I guess this was me doing deps upgrade without checking build results:

Code_Ozb9w4fl7J

image

We now can't trick typescript to emit ESM for commonjs project, we need a real ESM project to emit ESM code.

carlocorradini commented 6 months ago

@MichalLytek Yup, I've tried and we can't trick TypeScript anymore

MichalLytek commented 6 months ago

Should be fixed by 51ff280, will see in beta.5 if that works 😉

nemanjastanic commented 6 months ago

Thanks!

MichalLytek commented 6 months ago

@nemanjastanic Published v5, please check now if it works 😉

maplesteve commented 6 months ago

Published v5, please check now if it works 😉

@MichalLytek the v5-package is nearly empty; the build directory is missing.

dahaupt commented 6 months ago

@MichalLytek I can confirm that the build directory is missing in 2.0.0-beta.5.

MichalLytek commented 6 months ago

Thanks for the report. Our publish workflow is not working so I do publish by myself and something went wrong.

Should be ok now with 2.0.0-beta.6.

carlocorradini commented 6 months ago

Apologize if the CI/CD is currently broken 😔 It's my fault I'll fix it ASAP