3804 Cocos Creator Error

This is more of an answer than a question. If anyone gets Error: EngineErrorMap.md#3804 getComponent: Type must be non-nil with ScrollView, know that you must enable the module “layout” in project settings > module config. I ran into this error a couple of days ago and it took me a long time trying to diagnose it.

I figured if the ScrollView module is enabled and that this is all I need. I was confused because I use many getComponent calls in my script so I thought the error was due to my script and not ScrollView. If the error had more details, I would have figured it out sooner. I think error 3804 should display the name of the component you are trying to get so that you can better diagnose.

1 Like

Thank you for writing this. I will ask the engineering team to read this thread to see if there is anything they need to look at that might be the reason this error occurs.

I found out what was throwing the error and it’s in the ScrollView. Before figuring out the error, I looked at CCScrollView.js and did a search for getComponent and saw the line below. After installing the example cases on Github I realized that only my game had errors with ScrollView and then inspected the module config and noticed that ScrollView is dependent on the layout module. Once you know the problem, it’s no longer a problem but it’s easier if we had more information on which modules are dependent on other modules. My safest bet is to enable all modules but this would make my apps larger than necessary.

_calculateBoundary: function() {
        if (this.content) {
            //refresh content size
            var layout = this.content.getComponent(cc.Layout);
            if(layout && layout.enabledInHierarchy) {
                layout.updateLayout();
            }
            var scrollViewSize = this.node.getContentSize();

            var leftBottomPosition = this._convertToContentParentSpace(cc.p(0, 0));
            this._leftBoundary = leftBottomPosition.x;
            this._bottomBoundary = leftBottomPosition.y;

            var topRightPosition = this._convertToContentParentSpace(cc.p(scrollViewSize.width, scrollViewSize.height));
            this._rightBoundary = topRightPosition.x;
            this._topBoundary = topRightPosition.y;

            if(!CC_EDITOR) {
                this._moveContentToTopLeft(scrollViewSize);
            }
        }
    }
2 Likes

Great. I am glad you solved it.