You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Still getting __metadata is not defined using --env.roduction on Android #8925
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.
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.
`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');
@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 )
@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.
Activity
farfromrefug commentedon Oct 2, 2020
@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
kryptus36 commentedon Oct 2, 2020
@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();
}
}
`
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.
*/
`
farfromrefug commentedon Oct 2, 2020
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
kryptus36 commentedon Oct 2, 2020
I'll send an invite to your email.
kryptus36 commentedon Oct 2, 2020
@farfromrefug it's set up and sent to you. Hopefully you got it.
fix: ensure globals do not get tree shaked
farfromrefug commentedon Oct 3, 2020
@kryptus36 managed to get your project to work. It was a tree shaking issue. PR is already here #8931
fix(core): ensure globals do not get tree shaked (#8931)
NathanWalker commentedon Oct 3, 2020
Thanks to @farfromrefug this is now released in
7.0.10:https://github.com/NativeScript/NativeScript/releases/tag/7.0.10-core
farfromrefug commentedon Oct 3, 2020
@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 )
kryptus36 commentedon Oct 3, 2020
@farfromrefug Thanks very much, this is now working for me using "@nativescript/core": "~7.0.10"
NathanWalker commentedon Oct 3, 2020
@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.