[node-rsa] TypeError: util.inherits is not a function

ios
android

#1

When trying to include node-rsa got:

TypeError: util.inherits is not a function.

Repro steps:

vue init nativescript-vue/vue-cli-template repro
cd repro
npm install --save node-rsa
npm install

Add this line to HelloWorld.vue:

npm run watch:ios

***** Fatal JavaScript exception - application has been terminated. *****
Native stack trace:
1   0x104692c1f NativeScript::reportFatalErrorBeforeShutdown(JSC::ExecState*, JSC::Exception*, bool, bool)
2   0x1046c7caf -[TNSRuntime executeModule:referredBy:]
3   0x10414b441 main
4   0x10a137955 start
5   0x1
JavaScript stack trace:
1   @file:///app/app.js:13604:14
2   __webpack_require__@file:///app/app.js:20:34
3   @file:///app/app.js:36341:33
4   @file:///app/app.js:36601:34
5   __webpack_require__@file:///app/app.js:20:34
6   @file:///app/app.js:36311:33
7   __webpack_require__@file:///app/app.js:20:34
8   @file:///app/app.js:9649:30
9   __webpack_require__@file:///app/app.js:20:34
10  @file:///app/app.js:27449:30
11  @file:///app/app.js:27838:34
12  __webpack_require__@file:///app/app.js:20:34
13  @file:///app/app.js:27406:35
14  __webpack_require__@file:///app/app.js:20:34
15  @file:///app/app.js:27228:176
16  __webpack_require__@file:///app/app.js:20:34
17  @file:///app/app.js:13948:38
18  __webpack_require__@file:///app/app.js:20:34
19  @file:///app/app.js:63:37
20  anonymous@file:///app/app.js:64:12
21  evaluate@[native code]
22  moduleEvaluation@[native code]
23  @[native code]
24  promiseReactionJob@[native code]
JavaScript error:
file:///app/app.js:13604:14: JS ERROR TypeError: util.inherits is not a function. (In 'util.inherits(assert.AssertionError, Error)', 'util.inherits' is an instance of Object)

#2

That package seems to be written targeting node engine, it is not compatible NativeScript.


#3

Thanks Manoj! Any suggestion to work around this?


#4

Try the crypto libraries those targets browser or even the native plugin might work.