Typescript class conversion silently fails when using ES6 imports
See original GitHub issueEnvironment
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):
- CLI: 6.5.0
- Cross-platform modules:
- Android Runtime: 6.5.0-2020-03-12-110223-01
- iOS Runtime: 6.4.0
- Plugin(s):
Describe the bug
When defining a class that extends a native class (in my case an Android service) and using an ES6-style import at the top of the file, the class does not get converted to Java and is not included in the /platforms
folder. No error is given at bundling time.
To Reproduce
import { Utils } from '@nativescript/core';
@JavaProxy('com.belvederef.MyNotificationListener')
class MyNotificationListener extends android.service.notification
.NotificationListenerService {
constructor() {
super();
return global.__native(this);
}
onNotificationPosted(
sbn: android.service.notification.StatusBarNotification,
): void {
...
const context = Utils.android.getApplicationContext();
context.sendBroadcast(intent);
}
...
}
Expected behavior The class should be added to the platform folder or, if not possible to bundle with ES6-style imports, raise an error.
Additional context
I was able to solve the problem using node require()
imports in my method as below:
onNotificationPosted(
sbn: android.service.notification.StatusBarNotification,
): void {
...
const Utils = require('@nativescript/core').Utils;
const context = Utils.android.getApplicationContext();
context.sendBroadcast(intent);
}
}
ES6-style imports are shown as working on the documentation when extending native classes. I am not sure whether the error is caused by the object destructuring in the import, but when I use the same import with destructuring somewhere else in the app and it works.
For searchability’s sake, I got to know about the error due to a java.lang.ClassNotFoundException
raised at runtime.
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (5 by maintainers)
Top GitHub Comments
Just a follow up it seems to be a combination of both the vue version of the webpack config and something in the vue version of the TSConfig settings. I made a couple changes to the vue webpack config to take features from the straight ts webpack and then moved the tsconfig from the same app; and it built the JAVA code properly…
Here is a barebone project that reproduces the error https://github.com/belvederef/nativescript--8573. Have a look at the file
/app/services/MyNotificationListener.ts
; if you run the project as is, it will not generate the Java file but when you removeimport { Utils } from '@nativescript/core'
and uncomment this line you can see it will.