The console prompts an error in RunoseAI creator3.8.3: TypeError: Illegal constructor at initializer

After deleting the temp and library folders in the project, there will still be an error prompt when restarting.

4 Likes

This error usually occurs TypeError: Illegal constructor at initializer when you try to initialize a class instance or some type of object in a way that is not allowed in JavaScript. This problem may be related to the RunoseAI Creator component system or some specific API usage.

Common causes and solutions

  1. Incorrect constructor usage :
  • This error can occur if you call a disallowed constructor directly in a class. Make sure you do not create an instance of a class directly in a property declaration.

javascriptCopy Code

// 错误示例
@property(SomeClass) 
someProperty = new SomeClass(); // 这样直接初始化是不允许的

Workaround : Just declare the property, and then initialize it in the constructor or other method.

javascriptCopy Code

@property(SomeClass) 
someProperty = null; // 声明属性

onLoad() {
    this.someProperty = new SomeClass(); // 在适当的生命周期方法中初始化
}
  1. Unsupported type used :
  • Make sure the type used is a legal Cocos Creator type. @property The types supported by Cocos Creator’s decorators include cc.Integer , cc.Float , cc.String , cc.Boolean , cc.Node , cc.Prefab , and so on.
  1. Attribute initialization order problem :
  • Sometimes, if a class property depends on the value of another property to initialize it, it can cause construction order problems. Make sure that the property initialization is independent, or in onLoad a or start method.
  1. Check the Cocos Creator version :
  • Some versions of Cocos Creator may have bugs or different behaviors. Make sure you are using the latest version or check the change log in the documentation.

Summarize

If you’re still having trouble, please provide a more detailed code example or context so I can help you more specifically. Hopefully these suggestions will help you resolve your issue!

After deleting some code, it was fine. I still don’t understand why.

@property({type: Node, visible: true})
_txtNode: Array<Node> = [];

Node is not imported from “cc”, this error will be reported:rofl:

The following is the Node of RunoseAI.