eosjs icon indicating copy to clipboard operation
eosjs copied to clipboard

When importing JsSignature provider with common JS error occurs

Open JesseAbram opened this issue 7 years ago • 11 comments

Version of EOSJS "eosjs": "^20.0.0-beta3",

Describe the bug when using eosJS to send a transaction in common JS. Following the documentation provides this error.

const signatureProvider = new JsSignatureProvider(privateKeys);
                          ^

TypeError: JsSignatureProvider is not a constructor
    at Object.<anonymous> (/Users/jesse/Desktop/blockx/eosTest/sendTransaction.js:7:27)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Function.Module.runMain (module.js:693:10)
    at startup (bootstrap_node.js:191:16)
    at bootstrap_node.js:612:3

when console logging JsSignatureProvider you get

{ default: [Function: JsSignatureProvider] }

To Reproduce follow your documentation for sending a transaction with commonJS.

Expected behavior Receive a transaction hash

Desktop (please complete the following information):

  • macOS high Sierra

Additional context I have solved this problem in 2 ways. One was by importing as .default. This would require a documentation change. However, this issue is only seen in typescript when exporting default and not when using module.export. So I have created a PR that makes that change when exporting the JsSignatureProvider.

JesseAbram avatar Jan 03 '19 20:01 JesseAbram

created a PR that fixes this here

JesseAbram avatar Jan 03 '19 22:01 JesseAbram

Thanks for reporting @JesseAbram . Facing the same issue ((

i5hi avatar Jan 04 '19 08:01 i5hi

no worries btw fixed this in a hacky way. When importing Js signature provider, import it like this.

const JsSignatureProvider = require('eosjs/dist/eosjs-jssig').default;

JesseAbram avatar Jan 04 '19 17:01 JesseAbram

The current solution is to append .default to your require statement. In the near future, we will eliminate the need for this workaround this by removing all default exports.

c0d3ster avatar Jan 11 '19 22:01 c0d3ster

@JesseAbram Abram it seems like appending the .default doesn't work anymore. It did work for a while. But since I updated eosjs I've been getting the error. Please help

feekayo avatar Feb 06 '19 14:02 feekayo

ya, it seems like they fixed the issue with this PR https://github.com/EOSIO/eosjs/pull/490 . Try removing the .default now, that should work

JesseAbram avatar Feb 06 '19 15:02 JesseAbram

Yh. I tried it. Its doesnt work.. Here's snippets from my code. Maybe I'm doing something wrong

import JsSignatureProvider from 'eosjs/dist/eosjs-jssig'

const signatureProvider = new JsSignatureProvider([defaultPrivateKey]);

I keep getting the TypeError: __WEBPACK_IMPORTED_MODULE_3_eosjs_dist_eosjs_jssig___default.a is not a constructor

My eosjs@beta version is "^20.0.0-beta2"

feekayo avatar Feb 06 '19 16:02 feekayo

can you roll back the version to "eosjs": "^20.0.0-beta3", that I just checked is still working for me

JesseAbram avatar Feb 06 '19 19:02 JesseAbram

@feekayo in the 20.0.0-beta3 version, the correct way to import the JsSignatureProvider is as you have described in your comment... @JesseAbram PR #490 will not take effect until next release changing the syntax to a named import:

import { JsSignatureProvider } from 'eosjs/dist/eosjs-jssig

c0d3ster avatar Feb 06 '19 22:02 c0d3ster

I did the fix for beta3, but it only works with the private key provided in the examples for me. Using a different private key generated for my contracts, I get this error:

/node_modules/eosjs/dist/eosjs-jssig.js:76
            finally { if (e_1) throw e_1.error; }
                               ^

Error: Invalid checksum, a8b8d6d4 != 11e81458

edsonayllon avatar Mar 07 '19 05:03 edsonayllon

@edsonayllon I am also facing the same error, If you find out the solution please share

wdcs-lalitpatadiya avatar Jun 26 '20 04:06 wdcs-lalitpatadiya