CC 2.4.1 Script loading order

Can someone please help me with the scripts loading order on the build? For me it’s not making any sense! (I’m using web-mobile build to test it) On preview it works fine, this problem are only on builds

Before the 2.4, the scripts could be in any place of the project, but now it seems that the folder makes a lot of difference in the loading order!

What I noticed so far

  • Plugins should be loaded first, but they will not if they are in resources folder, they will load as a normal script
  • The normal scripts will run the require as soon as they are loaded, so it will crash if it requires another script that was not loaded yet

I think I’ve figured it something.

1st, There is a race condition in plugins / normal scripts loading, the plugins are not ensured to be loaded and runned before the normal scripts being loaded/runned. So, if you have a lot of plugins, even on the root of the project, some normal scripts can start running before they ended running the plugins.

In my case, when I putted all the scripts that defined global variables in the same folder, when the first normal script runned, the “const asd = require(window.Defs.ASD)” broke because Defs was not defined. It would be defined in the 10th plugin to be loaded, but only 5 were loaded at this point.

2nd, in top of the previous problem, the resources folder will only be loaded after all of this, so if you have any script there, they will be loaded after.

Here some example for you, if you run the build, you will see. (3.6 MB)

And, just to clarify, this was NOT occuring in < 2.4 versions. 2.4.1 didn’t fix any of this.

Interesting, I will bookmark this and see how my cc.2.3.3 -> 2.4.x transfer will go. I will let you know if I figure out something smart!

Thanks, I’ll check it

1 Like

It’s will be resolved in next version

1 Like

Thank you! When it release, I’ll check and answer here to confirm!

It’s released now

Isn’t he talking about 2.4.3?

I tested 2.4.2 with the test zip that I sended and the same error occured