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

ReferenceError: Cannot access 'XXX' before initialization #7005

Closed
leonard-henriquez opened this issue Mar 3, 2023 · 3 comments
Closed

ReferenceError: Cannot access 'XXX' before initialization #7005

leonard-henriquez opened this issue Mar 3, 2023 · 3 comments
Labels

Comments

@leonard-henriquez
Copy link

leonard-henriquez commented Mar 3, 2023

Describe the bug

SWC did not crash, but the app (NestJS) crashes at startup with the following error:

ReferenceError: Cannot access 'StepGraphQL' before initialization

Input code

input code

import { Field, ObjectType } from '@nestjs/graphql';
import { IsNumber, Min } from 'class-validator';
import { BaseModel } from '../../../common/graphql/base.gql-model';
import { TaskGraphQL } from '../../tasks/graphql/task.object';

@ObjectType('Step')
export class StepGraphQL extends BaseModel {
  @Field({ nullable: true })
  name?: string;

  @Field(() => [TaskGraphQL], { defaultValue: [] })
  tasks: TaskGraphQL[];

  @Field(() => String, { nullable: true })
  workspaceId?: string;

  @Field(() => String, { nullable: true })
  workspaceTemplateId?: string;

  @Field()
  @IsNumber()
  @Min(0)
  position: number;
}


output code is in reproduction link

Config

{
  "$schema": "https://json.schemastore.org/swcrc",
  "sourceMaps": true,
  "module": {
    "noInterop": false,
    "type": "commonjs"
  },
  "jsc": {
    "target": "es2017",
    "parser": {
      "syntax": "typescript",
      "decorators": true,
      "dynamicImport": true
    },
    "transform": {
      "legacyDecorator": true,
      "decoratorMetadata": true
    },
    "keepClassNames": true,
    "baseUrl": "./"
  },
  "minify": false
}

Playground link

Playground link

Expected behavior

I expect code to run without error

Actual behavior

App crashes at startup

Version

@swc/core: "^1.3.37"

Additional context

Im a using a NestJS app.
I followed this guide: https://docs.nestjs.com/recipes/swc.

@kdy1 kdy1 closed this as completed Mar 3, 2023
@leonard-henriquez
Copy link
Author

@kdy1 I'm sorry but I don't understand what's the problem and what the solution to my problem !

@swc-bot
Copy link
Collaborator

swc-bot commented Apr 2, 2023

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@swc-project swc-project locked as resolved and limited conversation to collaborators Apr 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

3 participants