Skip to content

Still getting __metadata is not defined using --env.roduction on Android #8925

Closed

Description

@kryptus36

Environment
Provide version numbers for the following components (information can be retrieved by running tns info in your project folder or by inspecting the package.json of the project):

✔ Getting NativeScript components versions information...
✔ Component nativescript has 7.0.8 version and is up to date.
✔ Component @nativescript/core has 7.0.9 version and is up to date.
✖ Component @nativescript/ios is not installed.
✔ Component @nativescript/android has 7.0.0 version and is up to date.

"dependencies": {
"@nativescript-community/ui-pager": "^13.0.0-alpha.10",
"@nativescript/core": "~7.0.9",
"@nativescript/firebase": "^11.0.0",
"@nativescript/iqkeyboardmanager": "^2.0.0",
"@types/node": "^12.12.7",
"moment": "^2.27.0",
"moment-timezone": "^0.5.28",
"@nativescript/appversion": "^2.0.0",
"nativescript-audio-player": "^1.0.3",
"@nativescript/geolocation": "^7.0.0",
"nativescript-insomnia": "^2.0.0",
"nativescript-mqtt": "^1.2.0",
"@nativescript/secure-storage": "^3.0.0",
"@nativescript/theme": "^3.0.0",
"nativescript-ui-listview": "^9.0.2",
"nativescript-ui-sidedrawer": "^9.0.3"
},
"devDependencies": {
"@nativescript/android": "7.0.0",
"@nativescript/types": "7.0.0",
"@nativescript/webpack": "~3.0.0",
"node-sass": "^4.14.1",
"tslint": "^6.1.1",
"typescript": "3.9.7"
},

Describe the bug
The app runs fine until I add --env.production. I then get:
System.err: java.lang.RuntimeException: Unable to create application com.tns.NativeScriptApplication: com.tns.NativeScriptException: Error calling module function
System.err: ReferenceError: __metadata is not defined

May be related to the bugs referenced in #8903 but that was apparently fixed.

To Reproduce
ns run android --emulator --env.production

Expected behavior
app runs

I did also make sure to run ns clean to make sure my build was fresh.

Activity

  1. farfromrefug commented on Oct 2, 2020

    @farfromrefug
    Collaborator

    @kryptus36 by any chance can you share your project ? If not maybe your app/main.ts ? It would help in figuring out why it still crashes

  2. kryptus36 commented on Oct 2, 2020

    @kryptus36
    Author

    @farfromrefug I could provide access privately to a few people.

    It is happening in an odd spot in the code. So you may need to see it. It's in here, line 5 when @ObservableProperty is called:

    `import { Observable } from '@nativescript/core';
    import { ObservableProperty } from '../../../shared/observable-property-decorator';

    export class BPCardSpace extends Observable {
    @ObservableProperty() number: number;
    @ObservableProperty() daubed: boolean;

    constructor(obj: any) {
    super();

    this.number = obj.number;
    this.daubed = obj.daubed;
    

    }
    }
    `

    Here's my app.ts:

    `import { getErrorService } from './globals/dependencies/locator';
    import { setApplicationEvents } from './globals/app-events/app-events';
    import { Trace, Application } from '@nativescript/core';

    /*
    Firebase init
    What if iOS doesn't show/receive notifications in the background?
    Make sure you require the plugin in app.ts / main.ts / main.aot.ts before application.start(),
    and do init() after the app has started (not in app.ts - not even in a timeout; move it out of app.ts entirely!).

    Make sure to use require, not import in app.ts because TSC will remove the import in case you're not using it.
    */
    const firebase = require('@nativescript/firebase');

    const errorHandler: Trace.DefaultErrorHandler = {
    handlerError(err: Error) {
    if (global.TNS_ENV === 'dev') {
    throw err;
    } else if (global.TNS_ENV === 'prod') {
    const errorService = getErrorService();
    errorService.reportError(err);
    }
    },
    };
    Trace.setErrorHandler(errorHandler);

    setApplicationEvents();

    Application.run({ moduleName: 'app-root' });

    /*
    Do not place any code after the application has been started as it will not
    be executed on iOS.
    */
    `

  3. farfromrefug commented on Oct 2, 2020

    @farfromrefug
    Collaborator

    Ok I think it happens because of.the first 2 lines of your app.ts.
    I could fix it if you give me access to your repo. If you are ok with it

  4. kryptus36 commented on Oct 2, 2020

    @kryptus36
    Author

    I'll send an invite to your email.

  5. kryptus36 commented on Oct 2, 2020

    @kryptus36
    Author

    @farfromrefug it's set up and sent to you. Hopefully you got it.

  6. farfromrefug commented on Oct 3, 2020

    @farfromrefug
    Collaborator

    @kryptus36 managed to get your project to work. It was a tree shaking issue. PR is already here #8931

  7. NathanWalker commented on Oct 3, 2020

    @NathanWalker
    Contributor
  8. farfromrefug commented on Oct 3, 2020

    @farfromrefug
    Collaborator

    @kryptus36 just please confirm it works for you. @NathanWalker i think we can now remove the imports of globals all around the core? (Except maybe android activity, I am not sure it is not still necessary there )

  9. kryptus36 commented on Oct 3, 2020

    @kryptus36
    Author

    @farfromrefug Thanks very much, this is now working for me using "@nativescript/core": "~7.0.10"

  10. NathanWalker commented on Oct 3, 2020

    @NathanWalker
    Contributor

    @farfromrefug most likely we can as sideEffects should handle things but let’s keep things way they are for a bit and can confirm privately to ensure any further change is all set.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions