当我尝试在Angular-NativeScript应用程序中使用工作程序(aka多线程)时,在应用程序执行期间找不到编译的工作程序文件。我在GitHub上发现了类似的问题,但是那里的说明并没有帮助我。
运行该应用程序将产生以下输出:
Project successfully built.
Installing on device 4865d3ab...
Successfully installed on device with identifier '4865d3ab'.
Refreshing application on device 4865d3ab...
Successfully synced application org.nativescript.app on device 4865d3ab.
JS: Angular is running in the development mode. Call enableProdMode() to enable the production mode.
JS: Warning: Setting the 'itemWidth' property of 'ListViewGridLayout' is not supported by the Android platform.
JS: Warning: Setting the 'itemHeight' property of 'ListViewGridLayout' is not supported by the Android platform.
JS: Warning: Setting the 'itemHeight' property of 'ListViewGridLayout' is not supported by the Android platform.
JS: Scan!
JS: Subnet: 192.168.2
JS: Permission is not granted (Error: com.tns.NativeScriptException: Failed to find module: "307b720bbe3cb7a8458a.worker.js", relative to: app/tns_modules/
JS: com.tns.Module.resolvePathHelper(Module.java:146)
JS: com.tns.Module.resolvePath(Module.java:55)
JS: com.tns.Runtime.callJSMethodNative(Native Method)
JS: com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1160)
JS: com.tns.Runtime.callJSMethodImpl(Runtime.java:1040)
JS: com.tns.Runtime.callJSMethod(Runtime.java:1027)
JS: com.tns.Runtime.callJSMethod(Runtime.java:1007)
JS: com.tns.Runtime.callJSMethod(Runtime.java:999)
JS: com.tns.NativeScriptActivity.onRequestPermissionsResult(NativeScriptActivity.java:58)
JS: android.app.Activity.dispatchRequestPermissionsResult(Activity.java:7630)
JS: android.app.Activity.dispatchActivityResult(Activity.java:7480)
JS: android.app.ActivityThread.deliverResults(ActivityThread.java:4489)
JS: android.app.ActivityThread.handleSendResult(ActivityThread.java:4538)
JS: android.app.servertransaction.ActivityResultItem.execu...
如何解决此问题? 非常感谢您的帮助。
编辑
我要通过以下方式导入该工人:
import TestWorker from 'worker-loader!./workers/test.worker.js'
工作者本身具有文件名test.worker.ts
和以下内容:
const context: Worker = self as any;
context.onmessage = msg => {
setTimeout(() => {
console.log('Inside TS worker...');
console.log(msg);
(<any>global).postMessage('TS Worker');
}, 500);
};
我在这里做错了什么?非常感谢您的帮助。你们真好。
答案 0 :(得分:0)
如果您按照Manoj的建议使用nativescript-worker-loader plugin,则需要使用以下命令导入worker
import TestWorker from 'nativescript-worker-loader!./workers/test.worker.js'
不配合
import TestWorker from 'worker-loader!./workers/test.worker.js'
您也可以使用
import TestWorker from 'nativescript-worker-loader!./workers/test.worker'
应该没什么区别。
还请确保按照nativescript-worker-loader readme中所述将typings/custom.d.ts
文件的模块声明为nativescript-worker-loader!*