When importing JsSignature provider with common JS error occurs
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.
created a PR that fixes this here
Thanks for reporting @JesseAbram . Facing the same issue ((
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;
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.
@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
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
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"
can you roll back the version to "eosjs": "^20.0.0-beta3", that I just checked is still working for me
@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
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 I am also facing the same error, If you find out the solution please share