如何在 nativeScript 中使用 fusionAuth 库?

How to use fusionAuth lib in nativeScript?

我尝试按照 nativescript 文档使用 lib,但是当我尝试使用它时,出现了一个我无法解决的错误,除了一些模块,如 net 和 tls,它无法自动找到它。使用 npm install 放置 tls 和 net 后我无法解决这个问题 'TypeError: Cannot read property' 浏览器 'of 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.access00(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.

很高兴看到人们使用 typescript 客户端。不幸的是,我们不直接支持 NativeScript,而且我们的 DefaultRESTClient 似乎导入了一些 NativeScript 不支持的东西。

要自行修复此问题,您需要使用 webpack 以与 NativeScript 兼容的自定义实现覆盖 DefaultRESTClient,或覆盖 [=10] 中使用的 cross-fetch 包=] 为 NativeScript 提供 fetch api 的东西。

您也可以在我们的 Github 上为 TypeScript 开一张票,建议 NativeScript 是您想要支持的东西,如果它获得足够多的投票或看起来很重要,我们将完成它应该支持