You are explicitly specifying `undefined` type to cc property "gameManager" of cc class "Lighty"

Hello, when I set the property type “GameManager” in my class “Lighty.ts” I got this error.
GameManager.ts imports the “Lighty” class too. It’s probablity why I got this error but I can’t understand how to fix this.

cr.mjs:15 Found possible circular reference in “http://localhost:7456/scripting/x/chunks/ce/cec23828dad35c5a650627fa53378b8a58384e48.js”, happened when use “GameManager” imported from “./GameManager” Error
at Object.execute (Lighty.ts:24:21)
at doExec (system.js:482:32)
at postOrderExec (system.js:472:23)
at system.js:461:30
at Array.forEach ()
at postOrderExec (system.js:459:12)
at system.js:461:30
at Array.forEach ()
at postOrderExec (system.js:459:12)
at system.js:406:14
report @ cr.mjs:15
debug.ts:80 You are explicitly specifying undefined type to cc property “gameManager” of cc class “Lighty”.
Is this intended? If not, this may indicate a circular reference.
For example:

// foo.ts
import { _decorator } from ‘cc’;
import { Bar } from ‘./bar’; // Given that ‘./bar’ also reference ‘foo.ts’.
// When importing ‘./bar’, execution of ‘./bar’ is hung on to wait execution of ‘foo.ts’,
// the Bar imported here is undefined until ‘./bar’ finish its execution.
// It leads to that
@_decorator.ccclass // ↓
export class Foo { // ↓
@_decorator.type(Bar) // → is equivalent to @_decorator.type(undefined)
public bar: Bar; // To eliminate this error, either:
// - Refactor your module structure(recommended), or
// - specify the type as cc class name: @_decorator.type('Bar'/* or any name you specified for Bar */)
}

Here is the property in my “Lighty” class

    //#region SerializeFields
    @property({ type: GameManager })
    public gameManager: GameManager = null;

And in my GameManager class

    @property(Lighty)
    public lighty: Lighty | null;

Thanks.

You are getting this error because of the circular dependency problem. Your script “Lighty.ts” is dependent on “GameManager.ts” and “GameManager.ts” is dependent on “Lighty.ts”.

To fix this keep your gameManager serialized in your “Lighty.ts” script and drag the GameManager node in the Inspector panel

In Lighty.ts

    @property(GameManager)
    gameManager: GameManager = null;

And in you “GameManager.ts” script use find(“Lighty”) to search the Lighty node and getComponent(Lighty) to get the Lighty component. Read more about accessing nodes and components.

In GameManager.ts

    lighty: Lighty = null;

    onLoad() {
        let lightyNode = find("Lighty");
        if(lightyNode){
            this.lighty = lightyNode.getComponent(Lighty);
        }

    }

Hello @theamirbeg

Thanks for your reply.

The fasted solution I found is to use Node type for GameManager.

    @property({ type: Node })
    public gameManager: GameManager = null;

Then I will use gameManager.getComponent(GameManager)