As of r226, Construct 3 supports JavaScript Modules, which brings significant improvements to the scripting feature. It also improves the loading time of preview, as it works around a Chrome bug that causes slow loading times in the old "classic" mode.
For technical reasons, the entire runtime and all third-party scripts all have to run in the same mode - either classic or modules mode. I would imagine most third-party addons do not need to make any change to support modules mode. However an issue came up with one third-party addon that suggests some addon developers will need to make changes. The necessary changes should be very small and quick to make, at the same level as routine bug fixes or maintenance that all responsible addon developers should already be doing. Also if addons are broken in modules mode, they are probably broken in other cases, such as after export, or when minifying, so these changes ought to have been made anyway regardless of the introduction of modules mode.
The Addon SDK downloads have all always used strict mode and per-file scopes, so are not affected by the following changes. It is only cases where external scripts have been brought in, or if addon developers have altered the SDK files to remove their strict mode or file scope.
JavaScript Modules - and Closure Compiler, which Construct uses for minifying code - are both used widely in the industry outside of Construct. So these changes are not specific to Construct: they are also necessary for compatibility with the wider JavaScript ecosystem.
For users
If you are using a third-party addon that is broken in modules mode, you can temporarily work around the problem by changing the Scripts type property (in the Advanced section of Project Properties) back to Classic. However this option is deprecated and will be removed in a few months, so you should contact the addon developer and ask them to make a small, quick update according to the information below.
Strict mode
JavaScript introduced a new strict mode in around 2011. This avoids common mistakes. See Strict mode on the MDN for more details. The old non-strict mode is called "sloppy" mode and is not recommended.
Modules mode runs all scripts in strict mode. If a third-party addon developer wrote code relying on features specific to sloppy mode and still had not updated it to use strict mode, it will now need to be updated.
One example of this is assigning to undeclared global variables is allowed to create a global variable in sloppy mode, but is an error in strict mode (to help catch accidental typos). For example:
// Assuming 'newVariable' is not declared anywhere else, this is
// allowed in sloppy mode, but throws an error in strict mode
newVariable = 10;
If the intent is to create a new global variable, explicitly add a property on the global object instead:
// Always works
globalThis.newVariable = 10;
Note: if addon developers have updated their code to work with the new script minifier - a change we announced several months ago in July 2020 - this type of usage should have already been corrected.
Module scope
In classic mode, variables declared at the top-level scope are available globally. In modules mode, variables declared at the top-level scope are only available within that module. For example:
// Classic mode: declares a global variable
// Module mode: only scoped to this module
let myGlobal = {};
Once again, the fix to this is to explicitly add properties on the global object:
// Works in both modes
globalThis.myGlobal = {};
Once again, this specific type of change is something that should already have been made since we switched to the new script minifier back in July, since Closure Compiler only supports the latter syntax.
Summary
In many cases nothing will need to be changed at all. In most other cases there will only need to be one or two lines of code changed.
For example one addon attempts to declare its namespace via a sloppy mode global assignment, i.e. MyNamespace = {}
. Once changed to a proper global property it should work again. The global property can also be declared as a local variable to avoid having to rewrite any more code, e.g.:
// Make local variable for this script
const MyNamespace = {};
// Also set as global variable for external calls
globalThis.MyNamespace = MyNamespace;
// Rest of script probably needs no further changes
Classic mode will be removed in a few months (likely by March 2021), so addon developers should make any necessary tweaks by then.