Error Minifying TypeScript Project

0 favourites
  • 7 posts
From the Asset Store
Use this game pack to create your own game, modify the existing game or simply take a look and see how it was made.
  • I encountered an issue when trying to minify my TypeScript project for web using "Simple" or "Advanced" mode:

    [JSC_LANGUAGE_FEATURE] This language feature is only supported for UNSTABLE mode or better: Public class fields.

    The error is from using public class fields, which are necessary for TypeScript, but also nice to have in vanilla JavaScript projects.

    Are there any recommended pipelines or solutions out there for working around this issue?

  • Google Closure Compiler doesn't support public class fields by default at the moment. Finding well-maintained up-to-date minifiers has always proven difficult. I looked at UglifyJS 3, but it hasn't been updated for a year, so it doesn't seem to be actively maintained. You can export unminified and try minifying with some other build tools (or Closure Compiler if you get the right flags to make it happy).

  • Thanks for the info, Ashley. I suspected that might be the case. I will minify after exporting for now.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I found a workaround for TypeScript projects: in tsconfig.json if you change "target" to "ES2021", it will transpile away public class fields (and private ones too, but with more complicated code). Then the resulting JavaScript should be compatible with Closure Compiler.

  • Works great for the “Simple” mode!

    Should this solution also work for the “Advanced” mode? I'm running into an issue:

    [JSC_UNDEFINED_VARIABLE] variable InstanceType is undeclared

    Main.ts

    import MySprite from './MySprite.js';
    
    runOnStartup(async runtime => {
     runtime.objects.MySprite.setInstanceClass(MySprite);
    });
    

    MySprite.ts

    export default class MySprite extends InstanceType.MySprite {
    }
    
  • That's not to do with TypeScript - as per this manual entry:

    One extra requirement of Advanced minifying is that global variables must always be referred to as a property of the global object.

    i.e. you must use globalThis.InstanceType.

  • Ah, makes sense. Thanks very much for the clarification.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)