When my project is packaged into the subnet, an error message appears
{
key: "covariant",
value: function(A) {
-> var t = Math.pow(BigInt(2), BigInt(this._bits-1)) * BigInt(-1)
->, e = Math.pow(BigInt(2), BigInt(this._bits-1))-BigInt(1);
if ("bigint" === typeof A)
return A >= t && A <= e;
if (Number.isInteger(A)) {
var n = BigInt(A);
return n >= t && n <= e
}
return !1
}
Uncaught (in promise) TypeError: Cannot convert a BigInt value to a number
I think when using Math, BigInt format should not be passed in as a parameter
Tried to rewrite the pow function, but caused other errors,
//This is a simple rewritten pow method
Math.pow = (...arg)=>{
for(let z of arg){
if (typeof z === "bigint"){
z = Number(z);
}
}
return pow(arg[0], arg[1]);
}
function pow(x, n) {
let result = x;
for (let i = 1; i <n; i++) {
result *= x;
}
return result;
}
This kind of error makes me very confused. I don’t know if it is the reason after babel is packaged, or the problem of dfinity package package after package.
At a certain point, it might be worth it to have a dedicated native-js package without BigInt, TextEncoder, or other assumptions from the browser/node package
I manually edited the idl.js file in the node_modules/@dfinity/agent/lib dir and switched the use of ** to a switch statement - it’s to determine if a given variable is within the bounds of the bit type etc. Bound to be simpler ways though (I couldn’t get babel skipping @babel/plugin-transform-exponentiation-operator disabled tho, which is the babel plugin causing the issues - probably the best solution).
Oh wait, @avi never said that they’re targeting React Native. If you are encountering the Math.pow error, consider updating your target ES version to ES2020. We don’t officially support anything older than that. Depending on your setup, that will be a tsconfig or browserslist update. We had that issue in GitHub - dfinity/cancan: A scalable video sharing service. and now have working configurations
Updating browserlist worked for me. Note: Be sure to delete the node_modules/.cache directory as otherwise new browserlist rules might not update in the build.