Here’s the latest error I’ve gotten in the midst of my battle:
Error: Failed while trying to deploy canisters.
Caused by: Failed while trying to deploy canisters.
Failed to build all canisters.
Failed while trying to build all canisters.
The post-build step failed for canister ‘y4oop-liaaa-aaaab-qacha-cai’ (hello_world_frontend) with an embedded error: Failed to build frontend for network ‘playground’.: The command ‘cd “/home/user/hello_world” && CANISTER_CANDID_PATH=“/home/user/hello_world/.dfx/playground/canisters/hello_world_frontend/assetstorage.did” CANISTER_CANDID_PATH_HELLO_WORLD_BACKEND=“/home/user/hello_world/.dfx/playground/canisters/hello_world_backend/hello_world_backend.did” CANISTER_CANDID_PATH_hello_world_backend=“/home/user/hello_world/.dfx/playground/canisters/hello_world_backend/hello_world_backend.did” CANISTER_ID=“y4oop-liaaa-aaaab-qacha-cai” CANISTER_ID_HELLO_WORLD_BACKEND=“ofoea-eyaaa-aaaab-qab6a-cai” CANISTER_ID_HELLO_WORLD_FRONTEND=“y4oop-liaaa-aaaab-qacha-cai” CANISTER_ID_hello_world_backend=“ofoea-eyaaa-aaaab-qab6a-cai” CANISTER_ID_hello_world_frontend=“y4oop-liaaa-aaaab-qacha-cai” DFX_NETWORK=“playground” DFX_VERSION=“0.15.2” HELLO_WORLD_BACKEND_CANISTER_ID=“ofoea-eyaaa-aaaab-qab6a-cai” HELLO_WORLD_FRONTEND_CANISTER_ID=“y4oop-liaaa-aaaab-qacha-cai” “npm” “run” “build”’ failed with exit status ‘exit status: 2’.
Stdout:
hello_world_frontend@0.1.0 prebuild
npm run generate
hello_world_frontend@0.1.0 generate
dfx generate hello_world_backend
hello_world_frontend@0.1.0 build
webpack
No production canister_ids.json found. Continuing with local
Stderr:
Building canisters before generate for Motoko
Generating type declarations for canister hello_world_backend:
src/declarations/hello_world_backend/hello_world_backend.did.d.ts
src/declarations/hello_world_backend/hello_world_backend.did.js
src/declarations/hello_world_backend/hello_world_backend.did
[webpack-cli] Failed to load ‘/home/user/hello_world/webpack.config.js’ config
[webpack-cli] TypeError: Cannot convert undefined or null to object
at Function.entries ()
at initCanisterEnv (/home/user/hello_world/webpack.config.js:30:17)
at Object. (/home/user/hello_world/webpack.config.js:37:30)
at Module._compile (node:internal/modules/cjs/loader:1376:14)
at Module._extensions…js (node:internal/modules/cjs/loader:1435:10)
at Module.load (node:internal/modules/cjs/loader:1207:32)
at Module._load (node:internal/modules/cjs/loader:1023:12)
at Module.require (node:internal/modules/cjs/loader:1235:19)
at require (node:internal/modules/helpers:176:18)
at WebpackCLI.tryRequireThenImport (/home/user/hello_world/node_modules/webpack-cli/lib/webpack-cli.js:204:22)
Next, I replaced this piece of original code (webpack.config) :
function initCanisterEnv() {
let localCanisters, prodCanisters;
try {
localCanisters = require(path.resolve(
“.dfx”,
“local”,
“canister_ids.json”
));
} catch (error) {
console.log(“No local canister_ids.json found. Continuing production”);
}
try {
prodCanisters = require(path.resolve(“canister_ids.json”));
} catch (error) {
console.log(“No production canister_ids.json found. Continuing with local”);
}
const network =
process.env.DFX_NETWORK ||
(process.env.NODE_ENV === “production” ? “ic” : “local”);
const canisterConfig = network === “local” ? localCanisters : prodCanisters;
return Object.entries(canisterConfig).reduce((prev, current) => {
const [canisterName, canisterDetails] = current;
prev[canisterName.toUpperCase() + “_CANISTER_ID”] =
canisterDetails[network];
return prev;
}, {});
}
const canisterEnvVariables = initCanisterEnv();
…replaced it with this. And it worked.
function initCanisterEnv() {
let localCanisters, prodCanisters;
try {
localCanisters = require(path.resolve(“.dfx”, “local”, “canister_ids.json”));
} catch (error) {
console.log(“No local canister_ids.json found. Continuing production”);
}
try {
prodCanisters = require(path.resolve(“canister_ids.json”));
} catch (error) {
console.log(“No production canister_ids.json found. Continuing with local”);
}
const network =
process.env.DFX_NETWORK ||
(process.env.NODE_ENV === “production” ? “ic” : “local”);
const canisterConfig = network === “local” ? localCanisters : prodCanisters;
// Check if canisterConfig is defined before using Object.entries
if (canisterConfig) {
return Object.entries(canisterConfig).reduce((prev, current) => {
const [canisterName, canisterDetails] = current;
prev[canisterName.toUpperCase() + “_CANISTER_ID”] =
canisterDetails[network];
return prev;
}, {});
}
return {};
}
const canisterEnvVariables = initCanisterEnv();