EXT JS 6 Application build after "C is not a constructor return new C (a[0])" Processing

Source: Internet
Author: User

Overview

After packaging the application for Ext JS 6, the following error occurs from time to time:

Because it is compressed after the error, to debug also can not start, so this error will make novice unprepared, do not know what is going on.

Cause of error

The main reason for this error is that the class being created is not included in the package or is caused by a class name error. One of the more typical mistakes I've encountered is the use of Ext.messagebox instead of Ext.window.MessageBox in requires, and this error occurs.

Solutions

Although it is known that the error is caused by the name of the class, but it is difficult to know that it is the requires in that file, it is also tricky to solve the problem, but there is plenty of patience and can be solved.

The error occurs in the Getinstantiator method in the Classmanager.js file in the application Ext\packages\core\src\class directory, the code is as follows:

Getinstantiator: function(length) {    varInstantiators = this.instantiators, Instantiator, I, args; Instantiator = Instantiators[length];if(!instantiator)        {i = length; args = []; for(i =0; i < length; i++) {Args.push (' a['+ i +'] '); } instantiator = Instantiators[length] =New  Function(' C ', ' A ', ' return new C (' + args.join(', ') + ') ');        //<debug>Instantiator.name ="Ext.create"+ length;//</debug>}returnInstantiator;},

The code in the error is generated automatically by the code "instantiator=" (895 lines of the file). The main purpose of this code is to create a new class instance and return the instance, and when the class does not exist or the class name is wrong, there will be an error if you cannot create an instance of the class.

Where the problem has been found, but to solve the problem, not here, because in the function to find is that class error, it is also difficult, because when the class is called to pass to the class may be an empty class name, so you need to check when the method is called.

By searching for Getinstantiator in the Classmanager.js file, you will find that the method is called within the Create method, with the following code:

Create function () {    varName =arguments[0], NameType =typeofName, args = Arrayslice.call (arguments,1), CLS;if(NameType = = =' function ') {CLS = name; }Else{if(NameType!==' String '&& Args.length = = =0) {args = [name];if(! (name = Name.xclass)) {name = args[0].xtype;if(name) {name =' Widgets. '+ Name; }            }        }//<debug>        if(typeofName!==' String '|| Name.length <1) {Throw New Error("[Ext.create] Invalid class name or alias '"+ name +"' specified, must be a non-empty string"); }//</debug>Name = Manager.resolvename (name);    CLS = Manager.get (name); }//Still not existing at this point, try-to-load it via synchronous mode as the last resort    if(!CLS) {//<debug>        //<if nonbrowser>!isnonbrowser &&//</if>Ext.log.warn ("[Ext.loader] synchronously loading '"+ name +"'; Consider adding "+"Ext.require ('"+ name +"') above Ext.onready");//</debug>Ext.syncrequire (name);    CLS = Manager.get (name); }//<debug>    if(!CLS) {Throw New Error("[Ext.create] Unrecognized class Name/alias:"+ name); }if(typeofCLS!==' function ') {Throw New Error("[ext.create] Singleton '"+ name +"' cannot be instantiated."); }//</debug>    returnManager.getinstantiator (Args.length) (CLS, args);},

Note the last sentence, you can see the call Getinstantiator method, passed two parameters, and the first parameter, according to the above code can know that this is the class name or class itself, at this time, generally by adding "Console.log (CLS)" On the return statement You can tell that there is a problem with that class.

The special case is that when the CLS is empty, you don't know where the error is. At this point, you need to add the debugger statement before the return statement, and when the method is called, the browser enters the debug state to check. In fact, this is a very annoying process, because the class creation process will call the method, so this needs patience, wait until the error occurs. And this process may have to be repeated once, because the error is generated after debugger, and you need to record when the error was generated, which is important.

When you know when the error occurred, you can debugger into the debug state, in the Browser debugging tool, view the stack information to determine that the class called the method caused by the error, so that the error is generated in the class. Know the error in that class, it is good to do, with the elimination of the law can easily know that the place is a problem.

Once the above steps have been modified, build and then Debug.

Because this error is difficult to restore, stack debugging can not be displayed in the picture, in this deep regret, if necessary, can be dabigatran 391747779 for consultation.

BTY: This error appears to have been eliminated in the latest version of Sencha cmd.

EXT JS 6 Application build after "C is not a constructor return new C (a[0])" Processing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.