Как использовать fusionAuth lib в nativeScript? - PullRequest
1 голос
/ 09 октября 2019

Я пытался использовать lib согласно документации на nativescript, но когда я пытаюсь использовать ее, возникает ошибка, которую я не могу устранить, кроме некоторых модулей, таких как net и tls, она не может найти ее автоматически. После использования npm install для установки tls и net, я не могу решить эту проблему 'TypeError: Невозможно прочитать свойство' browser 'undefined', и я не знаю, как решить эту проблему, чтобы проверить, работает ли lib нормально, я попытался использоватьionic 4 и он работал нормально, но в nativescript я обнаружил эту проблему как в Angular, так и в Vue.

Webpack compilation complete. Watching for file changes.
Webpack build done!
Successfully synced application org.nativescript.studyLogin on device 0aa24655.
Successfully transferred bundle.292d892ab2d871e6a00e.hot-update.js on device 0aa24655.
Successfully transferred 292d892ab2d871e6a00e.hot-update.json on device 0aa24655.
Successfully transferred bundle.js on device 0aa24655.
Successfully transferred runtime.js on device 0aa24655.
Successfully transferred vendor.js on device 0aa24655.
Restarting application on device 0aa24655...
Successfully synced application org.nativescript.studyLogin on device 0aa24655.
Successfully transferred bundle.e980eda364519dbb87a0.hot-update.js on device 0aa24655.
Successfully transferred e980eda364519dbb87a0.hot-update.json on device 0aa24655.
Refreshing application on device 0aa24655...
ActivityManager: Permission Denial: getCurrentUser() from pid=2971, uid=10187 requires android.permission.INTERACT_ACROSS_USERS
System.err: An uncaught Exception occurred on "main" thread.
System.err: Unable to create application com.tns.NativeScriptApplication: com.tns.NativeScriptException: Error calling module function 
System.err: TypeError: Cannot read property 'browser' of undefined
System.err: File: (file:///node_modules/pbkdf2/lib/default-encoding.js:3:11)
System.err: StackTrace: 
System.err:     ../node_modules/pbkdf2/lib/default-encoding.js(file:///node_modules/pbkdf2/lib/default-encoding.js:3:11)
System.err:     at __webpack_require__(file:///src/webpack/bootstrap:750:0)
System.err:     at fn(file:///src/webpack/bootstrap:120:0)
System.err:     at ../node_modules/pbkdf2/lib/sync.js(file:///node_modules/pbkdf2/lib/sync.js:14:22)
System.err:     at __webpack_require__(file:///src/webpack/bootstrap:750:0)
System.err:     at fn(file:///src/webpack/bootstrap:120:0)
System.err:     at ../node_modules/pbkdf2/index.js(file:///node_modules/pbkdf2/index.js:24:23)
System.err:     at __webpack_require__(file:///src/webpack/bootstrap:750:0)
System.err:     at fn(file:///src/webpack/bootstrap:120:0)
System.err:     at ../node_modules/crypto-browserify/index.js(file:///node_modules/crypto-browserify/index.js:14:8)
System.err:     at __webpack_require__(file:///src/webpack/bootstrap:750:0)
System.err:     at fn(file:///src/webpack/bootstrap:120:0)
System.err:     at ../node_modules/request/lib/helpers.js(file:///node_modules/request/lib/helpers.js:4:13)
System.err:     at __webpack_require__(file:///src/webpack/bootstrap:750:0)
System.err:     at fn(file:///src/webpack/bootstrap:120:0)
System.err:     at ../node_modules/request/index.js(file:///node_modules/request/index.js:19:14)
System.err:     at __webpack_require__(file:///src/webpack/bootstrap:750:0)
System.err:     at fn(file:///src/webpack/bootstrap:120:0)
System.err:     at ../node_modules/@fusionauth/typescript-client/build/src/DefaultRESTClient.js(file:///node_modules/@fusionauth/typescript-client/build/src/DefaultRESTClient.js:19:14)
System.err:     at __webpack_require__(file:///src/webpack/bootstrap:750:0)
System.err:     at fn(file:///src/webpack/bootstrap:120:0)
System.err:     at ../node_modules/@fusionauth/typescript-client/build/src/DefaultRESTClientBuilder.js(file:///node_modules/@fusionauth/typescript-client/build/src/DefaultRESTClientBuilder.js:18:28)
System.err:     at __webpack_require__(file:///src/webpack/bootstrap:750:0)
System.err:     at fn(file:///src/webpack/bootstrap:120:0)
System.err:     at ../node_modules/@fusionauth/typescript-client/build/src/FusionAuthClient.js(file:///node_modules/@fusionauth/typescript-client/build/src/FusionAuthClient.js:18:35)
System.err:     at __webpack_require__(file:///src/webpack/bootstrap:750:0)
System.err:     at fn(file:///src/webpack/bootstrap:120:0)
System.err:     at ../node_modules/@fusionauth/typescript-client/build/index.js(file:///node_modules/@fusionauth/typescript-client/build/index.js:21:9)
System.err:     at __webpack_require__(file:///src/webpack/bootstrap:750:0)
System.err:     at fn(file:///src/webpack/bootstrap:120:0)
System.err:     at ./app/lib/fusionAuthClientInstance.ts(file:///src/app/lib/fusionAuthClientInstance.ts:1:0)
System.err:     at __webpack_require__(file:///src/webpack/bootstrap:750:0)
System.err:     at fn(file:///src/webpack/bootstrap:120:0)
System.err:     at ./app/item/items.component.ts(file:///src/app/item/items.component.ts:1:0)
System.err:     at __webpack_require__(file:///src/webpack/bootstrap:750:0)
System.err:     at fn(file:///src/webpack/bootstrap:120:0)
System.err:     at ./app/app-routing.module.ts(file:///src/app/app-routing.module.ts:1:0)
System.err:     at __webpack_require__(file:///src/webpack/bootstrap:750:0)
System.err:     at fn(file:///src/webpack/bootstrap:120:0)
System.err:     at ./app/app.module.ts(file:///src/app/app.module.ts:1:0)
System.err:     at __webpack_require__(file:///src/webpack/bootstrap:750:0)
System.err:     at fn(file:///src/webpack/bootstrap:120:0)
System.err:     at (file:///data/data/org.nativescript.studyLogin/files/app/bundle.js:490:73)
System.err:     at ./main.ts(file:///data/data/org.nativescript.studyLogin/files/app/bundle.js:560:30)
System.err:     at __webpack_require__(file:///src/webpack/bootstrap:750:0)
System.err:     at checkDeferredModules(file:///src/webpack/bootstrap:43:0)
System.err:     at webpackJsonpCallback(file:///src/webpack/bootstrap:30:0)
System.err:     at (file:///data/data/org.nativescript.studyLogin/files/app/bundle.js:2:57)
System.err:     at require(:1:266)
System.err: TypeError: Cannot read property 'browser' of undefined
System.err: StackTrace:
System.err: java.lang.RuntimeException: Unable to create application com.tns.NativeScriptApplication: com.tns.NativeScriptException: Error calling module function 
System.err: TypeError: Cannot read property 'browser' of undefined
System.err: File: (file:///node_modules/pbkdf2/lib/default-encoding.js:3:11)
System.err: StackTrace: 
System.err:     ../node_modules/pbkdf2/lib/default-encoding.js(file:///node_modules/pbkdf2/lib/default-encoding.js:3:11)
System.err:     at __webpack_require__(file:///src/webpack/bootstrap:750:0)
System.err:     at fn(file:///src/webpack/bootstrap:120:0)
System.err:     at ../node_modules/pbkdf2/lib/sync.js(file:///node_modules/pbkdf2/lib/sync.js:14:22)
System.err:     at __webpack_require__(file:///src/webpack/bootstrap:750:0)
System.err:     at fn(file:///src/webpack/bootstrap:120:0)
System.err:     at ../node_modules/pbkdf2/index.js(file:///node_modules/pbkdf2/index.js:24:23)
System.err:     at __webpack_require__(file:///src/webpack/bootstrap:750:0)
System.err:     at fn(file:///src/webpack/bootstrap:120:0)
System.err:     at ../node_modules/crypto-browserify/index.js(file:///node_modules/crypto-browserify/index.js:14:8)
System.err:     at __webpack_require__(file:///src/webpack/bootstrap:750:0)
System.err:     at fn(file:///src/webpack/bootstrap:120:0)
System.err:     at ../node_modules/request/lib/helpers.js(file:///node_modules/request/lib/helpers.js:4:13)
System.err:     at __webpack_require__(file:///src/webpack/bootstrap:750:0)
System.err:     at fn(file:///src/webpack/bootstrap:120:0)
System.err:     at ../node_modules/request/index.js(file:///node_modules/request/index.js:19:14)
System.err:     at __webpack_require__(file:///src/webpack/bootstrap:750:0)
System.err:     at fn(file:///src/webpack/bootstrap:120:0)
System.err:     at ../node_modules/@fusionauth/typescript-client/build/src/DefaultRESTClient.js(file:///node_modules/@fusionauth/typescript-client/build/src/DefaultRESTClient.js:19:14)
System.err:     at __webpack_require__(file:///src/webpack/bootstrap:750:0)
System.err:     at fn(file:///src/webpack/bootstrap:120:0)
System.err:     at ../node_modules/@fusionauth/typescript-client/build/src/DefaultRESTClientBuilder.js(file:///node_modules/@fusionauth/typescript-client/build/src/DefaultRESTClientBuilder.js:18:28)
System.err:     at __webpack_require__(file:///src/webpack/bootstrap:750:0)
System.err:     at fn(file:///src/webpack/bootstrap:120:0)
System.err:     at ../node_modules/@fusionauth/typescript-client/build/src/FusionAuthClient.js(file:///node_modules/@fusionauth/typescript-client/build/src/FusionAuthClient.js:18:35)
System.err:     at __webpack_require__(file:///src/webpack/bootstrap:750:0)
System.err:     at fn(file:///src/webpack/bootstrap:120:0)
System.err:     at ../node_modules/@fusionauth/typescript-client/build/index.js(file:///node_modules/@fusionauth/typescript-client/build/index.js:21:9)
System.err:     at __webpack_require__(file:///src/webpack/bootstrap:750:0)
System.err:     at fn(file:///src/webpack/bootstrap:120:0)
System.err:     at ./app/lib/fusionAuthClientInstance.ts(file:///src/app/lib/fusionAuthClientInstance.ts:1:0)
System.err:     at __webpack_require__(file:///src/webpack/bootstrap:750:0)
System.err:     at fn(file:///src/webpack/bootstrap:120:0)
System.err:     at ./app/item/items.component.ts(file:///src/app/item/items.component.ts:1:0)
System.err:     at __webpack_require__(file:///src/webpack/bootstrap:750:0)
System.err:     at fn(file:///src/webpack/bootstrap:120:0)
System.err:     at ./app/app-routing.module.ts(file:///src/app/app-routing.module.ts:1:0)
System.err:     at __webpack_require__(file:///src/webpack/bootstrap:750:0)
System.err:     at fn(file:///src/webpack/bootstrap:120:0)
System.err:     at ./app/app.module.ts(file:///src/app/app.module.ts:1:0)
System.err:     at __webpack_require__(file:///src/webpack/bootstrap:750:0)
System.err:     at fn(file:///src/webpack/bootstrap:120:0)
System.err:     at (file:///data/data/org.nativescript.studyLogin/files/app/bundle.js:490:73)
System.err:     at ./main.ts(file:///data/data/org.nativescript.studyLogin/files/app/bundle.js:560:30)
System.err:     at __webpack_require__(file:///src/webpack/bootstrap:750:0)
System.err:     at checkDeferredModules(file:///src/webpack/bootstrap:43:0)
System.err:     at webpackJsonpCallback(file:///src/webpack/bootstrap:30:0)
System.err:     at (file:///data/data/org.nativescript.studyLogin/files/app/bundle.js:2:57)
System.err:     at require(:1:266)
System.err: TypeError: Cannot read property 'browser' of undefined
System.err:     at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4705)
System.err:     at android.app.ActivityThread.access$1400(ActivityThread.java:168)
System.err:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1389)
System.err:     at android.os.Handler.dispatchMessage(Handler.java:99)
System.err:     at android.os.Looper.loop(Looper.java:176)
System.err:     at android.app.ActivityThread.main(ActivityThread.java:5493)
System.err:     at java.lang.reflect.Method.invokeNative(Native Method)
System.err:     at java.lang.reflect.Method.invoke(Method.java:525)
System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1225)
System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1041)
System.err:     at dalvik.system.NativeStart.main(Native Method)
System.err: Caused by: com.tns.NativeScriptException: Error calling module function 
System.err: TypeError: Cannot read property 'browser' of undefined
System.err: File: (file:///node_modules/pbkdf2/lib/default-encoding.js:3:11)
System.err: StackTrace: 
System.err:     ../node_modules/pbkdf2/lib/default-encoding.js(file:///node_modules/pbkdf2/lib/default-encoding.js:3:11)
System.err:     at __webpack_require__(file:///src/webpack/bootstrap:750:0)
System.err:     at fn(file:///src/webpack/bootstrap:120:0)
System.err:     at ../node_modules/pbkdf2/lib/sync.js(file:///node_modules/pbkdf2/lib/sync.js:14:22)
System.err:     at __webpack_require__(file:///src/webpack/bootstrap:750:0)
System.err:     at fn(file:///src/webpack/bootstrap:120:0)
System.err:     at ../node_modules/pbkdf2/index.js(file:///node_modules/pbkdf2/index.js:24:23)
System.err:     at __webpack_require__(file:///src/webpack/bootstrap:750:0)
System.err:     at fn(file:///src/webpack/bootstrap:120:0)
System.err:     at ../node_modules/crypto-browserify/index.js(file:///node_modules/crypto-browserify/index.js:14:8)
System.err:     at __webpack_require__(file:///src/webpack/bootstrap:750:0)
System.err:     at fn(file:///src/webpack/bootstrap:120:0)
System.err:     at ../node_modules/request/lib/helpers.js(file:///node_modules/request/lib/helpers.js:4:13)
System.err:     at __webpack_require__(file:///src/webpack/bootstrap:750:0)
System.err:     at fn(file:///src/webpack/bootstrap:120:0)
System.err:     at ../node_modules/request/index.js(file:///node_modules/request/index.js:19:14)
System.err:     at __webpack_require__(file:///src/webpack/bootstrap:750:0)
System.err:     at fn(file:///src/webpack/bootstrap:120:0)
System.err:     at ../node_modules/@fusionauth/typescript-client/build/src/DefaultRESTClient.js(file:///node_modules/@fusionauth/typescript-client/build/src/DefaultRESTClient.js:19:14)
System.err:     at __webpack_require__(file:///src/webpack/bootstrap:750:0)
System.err:     at fn(file:///src/webpack/bootstrap:120:0)
System.err:     at ../node_modules/@fusionauth/typescript-client/build/src/DefaultRESTClientBuilder.js(file:///node_modules/@fusionauth/typescript-client/build/src/DefaultRESTClientBuilder.js:18:28)
System.err:     at __webpack_require__(file:///src/webpack/bootstrap:750:0)
System.err:     at fn(file:///src/webpack/bootstrap:120:0)
System.err:     at ../node_modules/@fusionauth/typescript-client/build/src/FusionAuthClient.js(file:///node_modules/@fusionauth/typescript-client/build/src/FusionAuthClient.js:18:35)
System.err:     at __webpack_require__(file:///src/webpack/bootstrap:750:0)
System.err:     at fn(file:///src/webpack/bootstrap:120:0)
System.err:     at ../node_modules/@fusionauth/typescript-client/build/index.js(file:///node_modules/@fusionauth/typescript-client/build/index.js:21:9)
System.err:     at __webpack_require__(file:///src/webpack/bootstrap:750:0)
System.err:     at fn(file:///src/webpack/bootstrap:120:0)
System.err:     at ./app/lib/fusionAuthClientInstance.ts(file:///src/app/lib/fusionAuthClientInstance.ts:1:0)
System.err:     at __webpack_require__(file:///src/webpack/bootstrap:750:0)
System.err:     at fn(file:///src/webpack/bootstrap:120:0)
System.err:     at ./app/item/items.component.ts(file:///src/app/item/items.component.ts:1:0)
System.err:     at __webpack_require__(file:///src/webpack/bootstrap:750:0)
System.err:     at fn(file:///src/webpack/bootstrap:120:0)
System.err:     at ./app/app-routing.module.ts(file:///src/app/app-routing.module.ts:1:0)
System.err:     at __webpack_require__(file:///src/webpack/bootstrap:750:0)
System.err:     at fn(file:///src/webpack/bootstrap:120:0)
System.err:     at ./app/app.module.ts(file:///src/app/app.module.ts:1:0)
System.err:     at __webpack_require__(file:///src/webpack/bootstrap:750:0)
System.err:     at fn(file:///src/webpack/bootstrap:120:0)
System.err:     at (file:///data/data/org.nativescript.studyLogin/files/app/bundle.js:490:73)
System.err:     at ./main.ts(file:///data/data/org.nativescript.studyLogin/files/app/bundle.js:560:30)
System.err:     at __webpack_require__(file:///src/webpack/bootstrap:750:0)
System.err:     at checkDeferredModules(file:///src/webpack/bootstrap:43:0)
System.err:     at webpackJsonpCallback(file:///src/webpack/bootstrap:30:0)
System.err:     at (file:///data/data/org.nativescript.studyLogin/files/app/bundle.js:2:57)
System.err:     at require(:1:266)
System.err: TypeError: Cannot read property 'browser' of undefined
System.err:     at com.tns.Runtime.runModule(Native Method)
System.err:     at com.tns.Runtime.runModule(Runtime.java:662)
System.err:     at com.tns.Runtime.run(Runtime.java:654)
System.err:     at com.tns.NativeScriptApplication.onCreate(NativeScriptApplication.java:21)
System.err:     at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1024)
System.err:     at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4702)
System.err:     ... 10 more
ActivityManager: Process org.nativescript.studyLogin (pid 2971) (adj 0) has died.
Successfully synced application org.nativescript.studyLogin on device 0aa24655.

1 Ответ

2 голосов
/ 09 октября 2019

Приятно видеть людей, использующих машинописный клиент. К сожалению, мы напрямую не поддерживаем NativeScript, и кажется, что наш DefaultRESTClient импортирует что-то, что NativeScript не поддерживает.

Чтобы исправить это самостоятельно, вам потребуется использовать веб-пакет для переопределения DefaultRESTClient с пользовательской реализацией, совместимой с NativeScript, или переопределить пакет cross-fetch, используемый внутри DefaultRESTClient, с чем-то, чтопредоставляет fetch API для NativeScript.

Вы также можете открыть тикет на нашем Github для TypeScript , предполагая, что NativeScript - это то, что вы хотели бы поддерживать, и мы завершим его, если его будет достаточноголосов или кажется чем-то важным, что мы должны поддержать.

...