To test deployment on the mainnet, I have deployed a very simple project where the frontend is written in JavaScript and the backend in Motoko. The project works well in the local development environment.
After deployment, the frontend canister is located at https://gn23t-ciaaa-aaaag-qcgsq-cai.icp0.io/. While running this canister, I encountered an error, and the message in the JavaScript console reads:
(anonymous) @ index.js:2
index.js:2 start checking balance
index.js:2 Uncaught (in promise) Error: Impossible to convert undefined to Principal.
at B.from (index.js:2:120970)
at index.js:2:244738
at kt.n [as checkBalance] (index.js:2:245662)
at Ft (index.js:2:246452)
at index.js:2:246619
The error occurred when the index.html is loaded, and a function Update in index.js is activated. The Update function is as follows:
async function update() {
console.log(“start checking balance”);
const currentAmount = await dbank.checkBalance();
console.log(“done checking balance.”);
document.getElementById(“value”).innerText = Math.round(currentAmount * 100) / 100;
};
As you can see, the message “start checking balance” is displayed in the console, but not the “done checking balance.”, meaning, the error occurred when the backend function dbank.checkBalance() was called.
The backend canister is accessible via the Candid interface at:
https://a4gq6-oaaaa-aaaab-qaa4q-cai.raw.ic0.app/?id=gk35h-pqaaa-aaaag-qcgsa-cai
The current dfx version is 0.14.3. The above error occurred when the dfx version in dfx.json is set to 0.13.1. When I changed the dfx version in dfx.json to be 0.14.3, I encountered a different error, as below:
(anonymous) @ index.js:2
index.js:2 start checking balance
index.js:2 Invalid asm.js: Unexpected token
index.js:2 Uncaught (in promise) Error: Failed to parse
at TA._decode (index.js:2:56852)
at TA.decodeFirst (index.js:2:56967)
at LA (index.js:2:149652)
at XA.query (index.js:2:155023)
at async index.js:2:244802
at async Ft (index.js:2:246420)
I have struggled with this deployment problem for a couple of days. I have read many posts, including:
- Error when calling canister method from React app
- I’m getting ‘Error: Impossible to convert undefined to Principal’ when calling motoko code
- Local Development with Internet Identity on M1 Apple Processor
I have tried suggestions by @kpeacock to check whether canisters are set up correctly in webpack.config.js via EnvironmentPlugin, matching process.env variables in the generated index.js in the folder of declarations. To ensure the canisters are given correct names, I have tried uncommenting lines 99, 101, and 102 in webpack.config.js, but I still encountered the same errors. Specifically, “Failed to parse” under dfx version 0.14.3 and “Impossible to convert undefined to Principal” under dfx version 0.13.1.
I have read many posts by @matthewhammer, @claudio, @Severin about deploying IC projects and about the new dfx release. I have also read dfx new release notes. Despite these efforts, I can’t figure out how to fix the problem.
The project codes are accessible at GitHub - yu970253/deploymentTest.
Can anybody help solve this problem? Best regards!