Skip to content

Syntax error in src/utils/tronWeb.js #26

@swansontec

Description

@swansontec

When we try to require @tronscan/client/src/utils/tronWeb.js, we get syntax errors on Node.js. It turns out that the same file can't contain ES6 export statements and CommonJS require statements, or various build tools will break.

We are currently using patch-package to patch @tronscan/[email protected]. Here is the diff we are using:

diff --git a/node_modules/@tronscan/client/src/utils/tronWeb.js b/node_modules/@tronscan/client/src/utils/tronWeb.js
index 6b1bc38..3f48a11 100644
--- a/node_modules/@tronscan/client/src/utils/tronWeb.js
+++ b/node_modules/@tronscan/client/src/utils/tronWeb.js
@@ -25,7 +25,7 @@ const {
 const fromHexString = hexString =>
   new Uint8Array(hexString.match(/.{1,2}/g).map(byte => parseInt(byte, 16)));
 
-export function transactionJsonToProtoBuf(transaction) {
+function transactionJsonToProtoBuf(transaction) {
   const rawData = transaction["raw_data"];
   const contractJson = rawData.contract[0];
   const transactionObj = contractJsonToProtobuf(contractJson);
@@ -52,7 +52,7 @@ export function transactionJsonToProtoBuf(transaction) {
   return transactionObj;
 }
 
-export function contractJsonToProtobuf(contract) {
+function contractJsonToProtobuf(contract) {
   const value = contract.parameter.value;
   switch (contract.type) {
 
@@ -365,3 +365,8 @@ export function contractJsonToProtobuf(contract) {
 
   }
 }
+
+module.exports = {
+  transactionJsonToProtoBuf,
+  contractJsonToProtobuf
+};

Of course, we would love to get this fix upstream.

This issue body was partially generated by patch-package.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions