From 7c8e2776f2d992227c17f5e760e779c3647ec30b Mon Sep 17 00:00:00 2001 From: Marco Walz Date: Thu, 27 Aug 2026 12:06:56 +0200 Subject: [PATCH 1/6] chore: drop dfx fallbacks and the dead CANISTER_ID_* env path MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit AGENTS.md:49 says to always use icp-cli and never dfx, but six frontends still carried dfx-era plumbing. Two of them (cert-var, flying_ninja) had a full `// Try dfx` branch in vite.config.js — `dfx ping` + `dfx canister id backend`, proxying to the dfx replica port 4943 — reached only when the icp-cli branch throws. Removed, along with the "or: dfx start --background && dfx deploy" half of the no-network error and the "or 'dfx deploy'" half of actor.js's missing-canister-ID error. They now match rust/qrcode, which was already icp-cli-only. All six also baked a dfx-only canister-ID fallback into the bundle: `loadEnv(mode, "..", ["CANISTER_"])` feeding a `process.env.CANISTER_ID_BACKEND` define, which actor.js consulted when the ic_env cookie had no canister ID. Those vars come from the `.env` dfx generates on deploy — a file AGENTS.md:91 forbids committing — so the fallback could never fire. Canister IDs now come from the cookie only, which is what icp-cli populates in both `icp deploy` and `vite dev`. Incidentally removed: `host: devConfig.host` in both who_am_i configs, always undefined since getDevServerConfig never returns a host (it was the dfx branch that set one). Kept deliberately: REPLICA_PORT (live — filevault and both who_am_i need it to reach II on the network port rather than the dev-server port), .github/workflows/ninja_pr_checks.yml (ICP Ninja genuinely runs dfx, @dfinity/ninja-devs-owned), and basic_ethereum's "dfx_test_key" (the literal management-canister key name on local replicas, not a dfx dependency). Verified: all 12 files parse; `npm run build` succeeds for rust/qrcode (define removed entirely) and motoko/who_am_i (define retained for REPLICA_PORT), with no unresolved process.env references in either bundle. Co-Authored-By: Claude Opus 5 (1M context) --- motoko/cert-var/frontend/src/actor.js | 7 +--- motoko/cert-var/frontend/vite.config.js | 43 ++------------------- motoko/filevault/frontend/src/actor.js | 4 +- motoko/filevault/frontend/vite.config.js | 8 +--- motoko/who_am_i/src/frontend/src/actor.js | 4 +- motoko/who_am_i/src/frontend/vite.config.js | 9 +---- rust/flying_ninja/frontend/src/actor.js | 7 +--- rust/flying_ninja/frontend/vite.config.js | 43 ++------------------- rust/qrcode/frontend/src/actor.js | 5 +-- rust/qrcode/frontend/vite.config.js | 12 +----- rust/who_am_i/src/frontend/src/actor.js | 4 +- rust/who_am_i/src/frontend/vite.config.js | 9 +---- 12 files changed, 22 insertions(+), 133 deletions(-) diff --git a/motoko/cert-var/frontend/src/actor.js b/motoko/cert-var/frontend/src/actor.js index 5c9079f4c2..d3098a6c28 100644 --- a/motoko/cert-var/frontend/src/actor.js +++ b/motoko/cert-var/frontend/src/actor.js @@ -7,14 +7,11 @@ import { createActor } from "./bindings/backend"; // via Set-Cookie header (see vite.config.js). const canisterEnv = safeGetCanisterEnv(); -// Resolve canister ID: cookie (icp-cli + dev server) → env var (dfx build-time) -const canisterId = - canisterEnv?.["PUBLIC_CANISTER_ID:backend"] ?? - process.env.CANISTER_ID_BACKEND; +const canisterId = canisterEnv?.["PUBLIC_CANISTER_ID:backend"]; if (!canisterId) { throw new Error( - "Canister ID for 'backend' not found. Run 'icp deploy' or 'dfx deploy' first." + "Canister ID for 'backend' not found. Run 'icp deploy' first." ); } diff --git a/motoko/cert-var/frontend/vite.config.js b/motoko/cert-var/frontend/vite.config.js index 4e49c4705d..3dde5b3551 100644 --- a/motoko/cert-var/frontend/vite.config.js +++ b/motoko/cert-var/frontend/vite.config.js @@ -1,9 +1,8 @@ -import { defineConfig, loadEnv } from "vite"; +import { defineConfig } from "vite"; import { execSync } from "child_process"; import { icpBindgen } from "@icp-sdk/bindgen/plugins/vite"; function getDevServerConfig() { - // Try icp-cli first try { const canisterId = execSync("icp canister status backend -e local -i", { encoding: "utf-8", @@ -27,44 +26,13 @@ function getDevServerConfig() { }; } catch {} - // Try dfx - try { - const pingResult = JSON.parse( - execSync("dfx ping", { encoding: "utf-8", stdio: "pipe" }) - ); - const rootKeyHex = Buffer.from(pingResult.root_key).toString("hex"); - const canisterId = execSync("dfx canister id backend", { - encoding: "utf-8", - stdio: "pipe", - }).trim(); - return { - headers: { - "Set-Cookie": `ic_env=${encodeURIComponent( - `ic_root_key=${rootKeyHex}&PUBLIC_CANISTER_ID:backend=${canisterId}` - )}; SameSite=Lax;`, - }, - proxy: { - "/api": { - target: "http://127.0.0.1:4943", - changeOrigin: true, - }, - }, - host: "127.0.0.1", - }; - } catch {} throw new Error( - "No local network running. Start with:\n icp network start -d && icp deploy\nor:\n dfx start --background && dfx deploy" + "No local network running. Start with:\n icp network start -d && icp deploy" ); } -export default defineConfig(({ command, mode }) => { - // dfx generates ../.env with CANISTER_ID_* vars on deploy. Bake them into the - // bundle so actor.js can fall back to them when the ic_env cookie does not - // contain canister IDs (dfx does not inject PUBLIC_CANISTER_ID:* env vars - // into the asset canister, unlike icp-cli). - const env = loadEnv(mode, "..", ["CANISTER_"]); - +export default defineConfig(({ command }) => { return { base: "./", plugins: [ @@ -73,11 +41,6 @@ export default defineConfig(({ command, mode }) => { outDir: "./src/bindings", }), ], - define: { - "process.env.CANISTER_ID_BACKEND": JSON.stringify( - env.CANISTER_ID_BACKEND - ), - }, optimizeDeps: { esbuildOptions: { define: { global: "globalThis" } }, }, diff --git a/motoko/filevault/frontend/src/actor.js b/motoko/filevault/frontend/src/actor.js index 0f364d30ff..e35f888b2d 100644 --- a/motoko/filevault/frontend/src/actor.js +++ b/motoko/filevault/frontend/src/actor.js @@ -3,9 +3,7 @@ import { createActor } from "./bindings/backend"; const canisterEnv = safeGetCanisterEnv(); -const canisterId = - canisterEnv?.["PUBLIC_CANISTER_ID:backend"] ?? - process.env.CANISTER_ID_BACKEND; +const canisterId = canisterEnv?.["PUBLIC_CANISTER_ID:backend"]; if (!canisterId) { throw new Error( diff --git a/motoko/filevault/frontend/vite.config.js b/motoko/filevault/frontend/vite.config.js index 0e61e065ac..774834eca0 100644 --- a/motoko/filevault/frontend/vite.config.js +++ b/motoko/filevault/frontend/vite.config.js @@ -1,4 +1,4 @@ -import { defineConfig, loadEnv } from "vite"; +import { defineConfig } from "vite"; import { execSync } from "child_process"; import react from "@vitejs/plugin-react"; import { icpBindgen } from "@icp-sdk/bindgen/plugins/vite"; @@ -33,8 +33,7 @@ function getDevServerConfig() { ); } -export default defineConfig(({ command, mode }) => { - const env = loadEnv(mode, "..", ["CANISTER_"]); +export default defineConfig(({ command }) => { const devConfig = command === "serve" ? getDevServerConfig() : undefined; return { @@ -47,9 +46,6 @@ export default defineConfig(({ command, mode }) => { }), ], define: { - "process.env.CANISTER_ID_BACKEND": JSON.stringify( - env.CANISTER_ID_BACKEND - ), "process.env.REPLICA_PORT": JSON.stringify(devConfig?.replicaPort ?? ""), }, optimizeDeps: { diff --git a/motoko/who_am_i/src/frontend/src/actor.js b/motoko/who_am_i/src/frontend/src/actor.js index 1e4ac04add..e3a4d83306 100644 --- a/motoko/who_am_i/src/frontend/src/actor.js +++ b/motoko/who_am_i/src/frontend/src/actor.js @@ -3,9 +3,7 @@ import { createActor } from "./bindings/backend"; const canisterEnv = safeGetCanisterEnv(); -const canisterId = - canisterEnv?.["PUBLIC_CANISTER_ID:backend"] ?? - process.env.CANISTER_ID_BACKEND; +const canisterId = canisterEnv?.["PUBLIC_CANISTER_ID:backend"]; if (!canisterId) { throw new Error( diff --git a/motoko/who_am_i/src/frontend/vite.config.js b/motoko/who_am_i/src/frontend/vite.config.js index 8bb840ac36..774834eca0 100644 --- a/motoko/who_am_i/src/frontend/vite.config.js +++ b/motoko/who_am_i/src/frontend/vite.config.js @@ -1,4 +1,4 @@ -import { defineConfig, loadEnv } from "vite"; +import { defineConfig } from "vite"; import { execSync } from "child_process"; import react from "@vitejs/plugin-react"; import { icpBindgen } from "@icp-sdk/bindgen/plugins/vite"; @@ -33,8 +33,7 @@ function getDevServerConfig() { ); } -export default defineConfig(({ command, mode }) => { - const env = loadEnv(mode, "../..", ["CANISTER_"]); +export default defineConfig(({ command }) => { const devConfig = command === "serve" ? getDevServerConfig() : undefined; return { @@ -47,9 +46,6 @@ export default defineConfig(({ command, mode }) => { }), ], define: { - "process.env.CANISTER_ID_BACKEND": JSON.stringify( - env.CANISTER_ID_BACKEND - ), "process.env.REPLICA_PORT": JSON.stringify(devConfig?.replicaPort ?? ""), }, optimizeDeps: { @@ -59,7 +55,6 @@ export default defineConfig(({ command, mode }) => { ? { headers: devConfig.headers, proxy: devConfig.proxy, - host: devConfig.host, } : undefined, }; diff --git a/rust/flying_ninja/frontend/src/actor.js b/rust/flying_ninja/frontend/src/actor.js index 2f487dbdb5..b21deeefd5 100644 --- a/rust/flying_ninja/frontend/src/actor.js +++ b/rust/flying_ninja/frontend/src/actor.js @@ -7,14 +7,11 @@ import { createActor } from "./bindings/backend"; // via Set-Cookie header (see vite.config.js). const canisterEnv = safeGetCanisterEnv(); -// Resolve canister ID: cookie (icp-cli + dev server) → env var (dfx build-time) -const canisterId = - canisterEnv?.["PUBLIC_CANISTER_ID:backend"] ?? - process.env.CANISTER_ID_BACKEND; +const canisterId = canisterEnv?.["PUBLIC_CANISTER_ID:backend"]; if (!canisterId) { throw new Error( - "Canister ID for 'backend' not found. Run 'icp deploy' or 'dfx deploy' first." + "Canister ID for 'backend' not found. Run 'icp deploy' first." ); } diff --git a/rust/flying_ninja/frontend/vite.config.js b/rust/flying_ninja/frontend/vite.config.js index b5ac17930c..9e1ef372da 100644 --- a/rust/flying_ninja/frontend/vite.config.js +++ b/rust/flying_ninja/frontend/vite.config.js @@ -1,10 +1,9 @@ -import { defineConfig, loadEnv } from "vite"; +import { defineConfig } from "vite"; import react from "@vitejs/plugin-react"; import { execSync } from "child_process"; import { icpBindgen } from "@icp-sdk/bindgen/plugins/vite"; function getDevServerConfig() { - // Try icp-cli first try { const canisterId = execSync("icp canister status backend -e local -i", { encoding: "utf-8", @@ -28,44 +27,13 @@ function getDevServerConfig() { }; } catch {} - // Try dfx - try { - const pingResult = JSON.parse( - execSync("dfx ping", { encoding: "utf-8", stdio: "pipe" }) - ); - const rootKeyHex = Buffer.from(pingResult.root_key).toString("hex"); - const canisterId = execSync("dfx canister id backend", { - encoding: "utf-8", - stdio: "pipe", - }).trim(); - return { - headers: { - "Set-Cookie": `ic_env=${encodeURIComponent( - `ic_root_key=${rootKeyHex}&PUBLIC_CANISTER_ID:backend=${canisterId}` - )}; SameSite=Lax;`, - }, - proxy: { - "/api": { - target: "http://127.0.0.1:4943", - changeOrigin: true, - }, - }, - host: "127.0.0.1", - }; - } catch {} throw new Error( - "No local network running. Start with:\n icp network start -d && icp deploy\nor:\n dfx start --background && dfx deploy" + "No local network running. Start with:\n icp network start -d && icp deploy" ); } -export default defineConfig(({ command, mode }) => { - // dfx generates ../.env with CANISTER_ID_* vars on deploy. Bake them into the - // bundle so actor.js can fall back to them when the ic_env cookie does not - // contain canister IDs (dfx does not inject PUBLIC_CANISTER_ID:* env vars - // into the asset canister, unlike icp-cli). - const env = loadEnv(mode, "..", ["CANISTER_"]); - +export default defineConfig(({ command }) => { return { base: "./", plugins: [ @@ -75,11 +43,6 @@ export default defineConfig(({ command, mode }) => { outDir: "./src/bindings", }), ], - define: { - "process.env.CANISTER_ID_BACKEND": JSON.stringify( - env.CANISTER_ID_BACKEND - ), - }, optimizeDeps: { esbuildOptions: { define: { global: "globalThis" } }, }, diff --git a/rust/qrcode/frontend/src/actor.js b/rust/qrcode/frontend/src/actor.js index 322a0601b4..9667a63427 100644 --- a/rust/qrcode/frontend/src/actor.js +++ b/rust/qrcode/frontend/src/actor.js @@ -7,10 +7,7 @@ import { createActor } from "./bindings/backend"; // via Set-Cookie header (see vite.config.js). const canisterEnv = safeGetCanisterEnv(); -// Resolve canister ID: cookie (icp-cli + dev server) → env var (dfx build-time) -const canisterId = - canisterEnv?.["PUBLIC_CANISTER_ID:backend"] ?? - process.env.CANISTER_ID_BACKEND; +const canisterId = canisterEnv?.["PUBLIC_CANISTER_ID:backend"]; if (!canisterId) { throw new Error( diff --git a/rust/qrcode/frontend/vite.config.js b/rust/qrcode/frontend/vite.config.js index cfa898e9d0..36322ccb72 100644 --- a/rust/qrcode/frontend/vite.config.js +++ b/rust/qrcode/frontend/vite.config.js @@ -1,9 +1,8 @@ -import { defineConfig, loadEnv } from "vite"; +import { defineConfig } from "vite"; import { execSync } from "child_process"; import { icpBindgen } from "@icp-sdk/bindgen/plugins/vite"; function getDevServerConfig() { - // Try icp-cli first try { const canisterId = execSync("icp canister status backend -e local -i", { encoding: "utf-8", @@ -32,9 +31,7 @@ function getDevServerConfig() { ); } -export default defineConfig(({ command, mode }) => { - const env = loadEnv(mode, "..", ["CANISTER_"]); - +export default defineConfig(({ command }) => { return { base: "./", plugins: [ @@ -43,11 +40,6 @@ export default defineConfig(({ command, mode }) => { outDir: "./src/bindings", }), ], - define: { - "process.env.CANISTER_ID_BACKEND": JSON.stringify( - env.CANISTER_ID_BACKEND - ), - }, optimizeDeps: { esbuildOptions: { define: { global: "globalThis" } }, }, diff --git a/rust/who_am_i/src/frontend/src/actor.js b/rust/who_am_i/src/frontend/src/actor.js index 1e4ac04add..e3a4d83306 100644 --- a/rust/who_am_i/src/frontend/src/actor.js +++ b/rust/who_am_i/src/frontend/src/actor.js @@ -3,9 +3,7 @@ import { createActor } from "./bindings/backend"; const canisterEnv = safeGetCanisterEnv(); -const canisterId = - canisterEnv?.["PUBLIC_CANISTER_ID:backend"] ?? - process.env.CANISTER_ID_BACKEND; +const canisterId = canisterEnv?.["PUBLIC_CANISTER_ID:backend"]; if (!canisterId) { throw new Error( diff --git a/rust/who_am_i/src/frontend/vite.config.js b/rust/who_am_i/src/frontend/vite.config.js index 8bb840ac36..774834eca0 100644 --- a/rust/who_am_i/src/frontend/vite.config.js +++ b/rust/who_am_i/src/frontend/vite.config.js @@ -1,4 +1,4 @@ -import { defineConfig, loadEnv } from "vite"; +import { defineConfig } from "vite"; import { execSync } from "child_process"; import react from "@vitejs/plugin-react"; import { icpBindgen } from "@icp-sdk/bindgen/plugins/vite"; @@ -33,8 +33,7 @@ function getDevServerConfig() { ); } -export default defineConfig(({ command, mode }) => { - const env = loadEnv(mode, "../..", ["CANISTER_"]); +export default defineConfig(({ command }) => { const devConfig = command === "serve" ? getDevServerConfig() : undefined; return { @@ -47,9 +46,6 @@ export default defineConfig(({ command, mode }) => { }), ], define: { - "process.env.CANISTER_ID_BACKEND": JSON.stringify( - env.CANISTER_ID_BACKEND - ), "process.env.REPLICA_PORT": JSON.stringify(devConfig?.replicaPort ?? ""), }, optimizeDeps: { @@ -59,7 +55,6 @@ export default defineConfig(({ command, mode }) => { ? { headers: devConfig.headers, proxy: devConfig.proxy, - host: devConfig.host, } : undefined, }; From 3b667107b322830f509eed0ddb1c9ef7b45c6046 Mon Sep 17 00:00:00 2001 From: Marco Walz Date: Thu, 27 Aug 2026 12:24:58 +0200 Subject: [PATCH 2/6] chore: stop advertising dfx_test_key MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Supersedes this branch's earlier claim that basic_ethereum's "dfx_test_key" had to stay. It did not: the local network (PocketIC) provisions test_key_1 and key_1 to mimic mainnet, so dfx_test_key is not needed to develop locally, and the repo already uses test_key_1 everywhere it actually names a key. All three remaining mentions were comments, not usage: - rust/basic_ethereum/backend/lib.rs — the InitArg doc comment offered "dfx_test_key" (local dfx) as the local-development choice. Now names only test_key_1 (works on the local network and mainnet) and key_1 (mainnet production), matching threshold-ecdsa and x509. - rust/threshold-schnorr and rust/x509 integration tests — comments noting that with_test_threshold_keys_subnet() also provides dfx_test_key. True but beside the point; both tests use test_key_1. `grep` for dfx_test_key now returns nothing. `cargo check --target wasm32-unknown-unknown` passes for basic_ethereum. Co-Authored-By: Claude Opus 5 (1M context) --- rust/basic_ethereum/backend/lib.rs | 6 +++--- rust/threshold-schnorr/backend/tests/integration_tests.rs | 3 +-- rust/x509/backend/tests/integration_tests.rs | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/rust/basic_ethereum/backend/lib.rs b/rust/basic_ethereum/backend/lib.rs index 6d8d0fdadb..d67e0a695d 100644 --- a/rust/basic_ethereum/backend/lib.rs +++ b/rust/basic_ethereum/backend/lib.rs @@ -256,9 +256,9 @@ fn estimate_transaction_fees() -> (u128, u128, u128) { #[derive(CandidType, Deserialize, Debug, Default, PartialEq, Eq)] pub struct InitArg { pub ethereum_network: Option, - /// ECDSA key name as used by the IC management canister: "dfx_test_key" (local dfx), - /// "test_key_1" (ICP mainnet testing), or "key_1" (ICP mainnet production). - /// Defaults to "test_key_1". + /// ECDSA key name as used by the IC management canister: "test_key_1" (test key, + /// works on both the local network and ICP mainnet) or "key_1" (ICP mainnet + /// production). Defaults to "test_key_1". pub ecdsa_key_name: Option, } diff --git a/rust/threshold-schnorr/backend/tests/integration_tests.rs b/rust/threshold-schnorr/backend/tests/integration_tests.rs index 0079b81168..1528a9a5a9 100644 --- a/rust/threshold-schnorr/backend/tests/integration_tests.rs +++ b/rust/threshold-schnorr/backend/tests/integration_tests.rs @@ -8,8 +8,7 @@ use serde::Deserialize; /// (absent, empty, invalid length, valid 32 bytes) for sign+verify, plus negative cases. /// /// The PocketIC instance is reused across iterations for speed. -/// The test threshold keys subnet provides `test_key_1` and `dfx_test_key`, matching -/// the canister's default key (`test_key_1`). +/// The test threshold keys subnet provides `test_key_1`, the canister's default key. #[test] fn signing_and_verification_should_work_correctly() { const ALGORITHMS: [SchnorrAlgorithm; 2] = diff --git a/rust/x509/backend/tests/integration_tests.rs b/rust/x509/backend/tests/integration_tests.rs index 139974aa7c..9fccc8f45c 100644 --- a/rust/x509/backend/tests/integration_tests.rs +++ b/rust/x509/backend/tests/integration_tests.rs @@ -19,7 +19,7 @@ fn load_wasm() -> Vec { } fn pic_and_canister_id(ca_key_information: CaKeyInformation) -> (pocket_ic::PocketIc, Principal) { - // with_test_threshold_keys_subnet provides test_key_1 and dfx_test_key for all algorithms. + // with_test_threshold_keys_subnet provides test_key_1 for all algorithms. let pic = PocketIcBuilder::new() .with_application_subnet() .with_test_threshold_keys_subnet() From 48e8312ceb9efceb255c380fad4b484aae052115 Mon Sep 17 00:00:00 2001 From: Marco Walz Date: Thu, 27 Aug 2026 12:59:38 +0200 Subject: [PATCH 3/6] fix: dev-server error message conflated "no network" with "not deployed" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Copilot flagged this on the two configs this branch already touched, and it is right — the failure is in fact broader than the review said. `getDevServerConfig()` wraps both `icp canister status backend -e local -i` and `icp network status --json` in one try/catch, then reports "No local network running". But `icp canister status` is the first call and it fails on a *canister-ID lookup*, before it ever reaches the network: $ icp canister status frontend -e local -i # network DOWN Error: failed to lookup canister ID for canister 'frontend' ... $ icp canister status frontend -e local -i # network UP, not deployed Error: failed to lookup canister ID for canister 'frontend' ... Identical either way, so a running-but-undeployed project is told its network is down. The suggested remedy already covered both cases; only the diagnosis was wrong. Reworded in all 15 configs that carry it, not just the two flagged — motoko/{cert-var,daily_planner,filevault,flying_ninja,random_maze, superheroes,who_am_i,vetkeys/basic_vetkd, vetkeys/password_manager_with_metadata} and the rust twins plus rust/qrcode. Also tidied the double blank line left where the dfx branch was removed in cert-var and flying_ninja. Note for a follow-up: the hello_world / llm_chatbot / evm_block_explorer / image-classification / face-recognition configs already have the better structure — `icp network status` outside the try, and a separate try/catch around the canister lookup with its own "deploy the backend" message. Converging the other 15 on that shape would remove the ambiguity rather than reword it. Co-Authored-By: Claude Opus 5 (1M context) --- motoko/cert-var/frontend/vite.config.js | 3 +-- motoko/daily_planner/frontend/vite.config.js | 2 +- motoko/filevault/frontend/vite.config.js | 2 +- motoko/flying_ninja/frontend/vite.config.js | 2 +- motoko/random_maze/frontend/vite.config.js | 2 +- motoko/superheroes/frontend/vite.config.js | 2 +- motoko/vetkeys/basic_vetkd/frontend/vite.config.js | 2 +- .../password_manager_with_metadata/frontend/vite.config.js | 2 +- motoko/who_am_i/src/frontend/vite.config.js | 2 +- rust/daily_planner/frontend/vite.config.js | 2 +- rust/flying_ninja/frontend/vite.config.js | 3 +-- rust/qrcode/frontend/vite.config.js | 2 +- rust/vetkeys/basic_vetkd/frontend/vite.config.js | 2 +- .../password_manager_with_metadata/frontend/vite.config.js | 2 +- rust/who_am_i/src/frontend/vite.config.js | 2 +- 15 files changed, 15 insertions(+), 17 deletions(-) diff --git a/motoko/cert-var/frontend/vite.config.js b/motoko/cert-var/frontend/vite.config.js index 3dde5b3551..28522e1aae 100644 --- a/motoko/cert-var/frontend/vite.config.js +++ b/motoko/cert-var/frontend/vite.config.js @@ -26,9 +26,8 @@ function getDevServerConfig() { }; } catch {} - throw new Error( - "No local network running. Start with:\n icp network start -d && icp deploy" + "No local network running, or 'backend' is not deployed yet. Run:\n icp network start -d && icp deploy" ); } diff --git a/motoko/daily_planner/frontend/vite.config.js b/motoko/daily_planner/frontend/vite.config.js index 1b9599b191..2f8cc83937 100644 --- a/motoko/daily_planner/frontend/vite.config.js +++ b/motoko/daily_planner/frontend/vite.config.js @@ -28,7 +28,7 @@ function getDevServerConfig() { } catch {} throw new Error( - "No local network running. Start with:\n icp network start -d && icp deploy" + "No local network running, or 'backend' is not deployed yet. Run:\n icp network start -d && icp deploy" ); } diff --git a/motoko/filevault/frontend/vite.config.js b/motoko/filevault/frontend/vite.config.js index 774834eca0..ca525f7b20 100644 --- a/motoko/filevault/frontend/vite.config.js +++ b/motoko/filevault/frontend/vite.config.js @@ -29,7 +29,7 @@ function getDevServerConfig() { } catch {} throw new Error( - "No local network running. Start with:\n icp network start -d && icp deploy" + "No local network running, or 'backend' is not deployed yet. Run:\n icp network start -d && icp deploy" ); } diff --git a/motoko/flying_ninja/frontend/vite.config.js b/motoko/flying_ninja/frontend/vite.config.js index d1495b37ce..07b4f0c2dd 100644 --- a/motoko/flying_ninja/frontend/vite.config.js +++ b/motoko/flying_ninja/frontend/vite.config.js @@ -29,7 +29,7 @@ function getDevServerConfig() { } catch {} throw new Error( - "No local network running. Start with:\n icp network start -d && icp deploy" + "No local network running, or 'backend' is not deployed yet. Run:\n icp network start -d && icp deploy" ); } diff --git a/motoko/random_maze/frontend/vite.config.js b/motoko/random_maze/frontend/vite.config.js index 1b9599b191..2f8cc83937 100644 --- a/motoko/random_maze/frontend/vite.config.js +++ b/motoko/random_maze/frontend/vite.config.js @@ -28,7 +28,7 @@ function getDevServerConfig() { } catch {} throw new Error( - "No local network running. Start with:\n icp network start -d && icp deploy" + "No local network running, or 'backend' is not deployed yet. Run:\n icp network start -d && icp deploy" ); } diff --git a/motoko/superheroes/frontend/vite.config.js b/motoko/superheroes/frontend/vite.config.js index fcc1308780..290fd63251 100644 --- a/motoko/superheroes/frontend/vite.config.js +++ b/motoko/superheroes/frontend/vite.config.js @@ -29,7 +29,7 @@ function getDevServerConfig() { } catch {} throw new Error( - "No local network running. Start with:\n icp network start -d && icp deploy" + "No local network running, or 'backend' is not deployed yet. Run:\n icp network start -d && icp deploy" ); } diff --git a/motoko/vetkeys/basic_vetkd/frontend/vite.config.js b/motoko/vetkeys/basic_vetkd/frontend/vite.config.js index 72777742b0..b0a8fe5d5f 100644 --- a/motoko/vetkeys/basic_vetkd/frontend/vite.config.js +++ b/motoko/vetkeys/basic_vetkd/frontend/vite.config.js @@ -27,7 +27,7 @@ function getDevServerConfig() { } catch {} throw new Error( - "No local network running. Start with:\n icp network start -d && icp deploy" + "No local network running, or 'backend' is not deployed yet. Run:\n icp network start -d && icp deploy" ); } diff --git a/motoko/vetkeys/password_manager_with_metadata/frontend/vite.config.js b/motoko/vetkeys/password_manager_with_metadata/frontend/vite.config.js index 169539f3bb..531175c7c3 100644 --- a/motoko/vetkeys/password_manager_with_metadata/frontend/vite.config.js +++ b/motoko/vetkeys/password_manager_with_metadata/frontend/vite.config.js @@ -31,7 +31,7 @@ function getDevServerConfig() { } catch {} throw new Error( - "No local network running. Start with:\n icp network start -d && icp deploy" + "No local network running, or 'backend' is not deployed yet. Run:\n icp network start -d && icp deploy" ); } diff --git a/motoko/who_am_i/src/frontend/vite.config.js b/motoko/who_am_i/src/frontend/vite.config.js index 774834eca0..ca525f7b20 100644 --- a/motoko/who_am_i/src/frontend/vite.config.js +++ b/motoko/who_am_i/src/frontend/vite.config.js @@ -29,7 +29,7 @@ function getDevServerConfig() { } catch {} throw new Error( - "No local network running. Start with:\n icp network start -d && icp deploy" + "No local network running, or 'backend' is not deployed yet. Run:\n icp network start -d && icp deploy" ); } diff --git a/rust/daily_planner/frontend/vite.config.js b/rust/daily_planner/frontend/vite.config.js index 1b9599b191..2f8cc83937 100644 --- a/rust/daily_planner/frontend/vite.config.js +++ b/rust/daily_planner/frontend/vite.config.js @@ -28,7 +28,7 @@ function getDevServerConfig() { } catch {} throw new Error( - "No local network running. Start with:\n icp network start -d && icp deploy" + "No local network running, or 'backend' is not deployed yet. Run:\n icp network start -d && icp deploy" ); } diff --git a/rust/flying_ninja/frontend/vite.config.js b/rust/flying_ninja/frontend/vite.config.js index 9e1ef372da..c05bb593a2 100644 --- a/rust/flying_ninja/frontend/vite.config.js +++ b/rust/flying_ninja/frontend/vite.config.js @@ -27,9 +27,8 @@ function getDevServerConfig() { }; } catch {} - throw new Error( - "No local network running. Start with:\n icp network start -d && icp deploy" + "No local network running, or 'backend' is not deployed yet. Run:\n icp network start -d && icp deploy" ); } diff --git a/rust/qrcode/frontend/vite.config.js b/rust/qrcode/frontend/vite.config.js index 36322ccb72..28522e1aae 100644 --- a/rust/qrcode/frontend/vite.config.js +++ b/rust/qrcode/frontend/vite.config.js @@ -27,7 +27,7 @@ function getDevServerConfig() { } catch {} throw new Error( - "No local network running. Start with:\n icp network start -d && icp deploy" + "No local network running, or 'backend' is not deployed yet. Run:\n icp network start -d && icp deploy" ); } diff --git a/rust/vetkeys/basic_vetkd/frontend/vite.config.js b/rust/vetkeys/basic_vetkd/frontend/vite.config.js index 72777742b0..b0a8fe5d5f 100644 --- a/rust/vetkeys/basic_vetkd/frontend/vite.config.js +++ b/rust/vetkeys/basic_vetkd/frontend/vite.config.js @@ -27,7 +27,7 @@ function getDevServerConfig() { } catch {} throw new Error( - "No local network running. Start with:\n icp network start -d && icp deploy" + "No local network running, or 'backend' is not deployed yet. Run:\n icp network start -d && icp deploy" ); } diff --git a/rust/vetkeys/password_manager_with_metadata/frontend/vite.config.js b/rust/vetkeys/password_manager_with_metadata/frontend/vite.config.js index 169539f3bb..531175c7c3 100644 --- a/rust/vetkeys/password_manager_with_metadata/frontend/vite.config.js +++ b/rust/vetkeys/password_manager_with_metadata/frontend/vite.config.js @@ -31,7 +31,7 @@ function getDevServerConfig() { } catch {} throw new Error( - "No local network running. Start with:\n icp network start -d && icp deploy" + "No local network running, or 'backend' is not deployed yet. Run:\n icp network start -d && icp deploy" ); } diff --git a/rust/who_am_i/src/frontend/vite.config.js b/rust/who_am_i/src/frontend/vite.config.js index 774834eca0..ca525f7b20 100644 --- a/rust/who_am_i/src/frontend/vite.config.js +++ b/rust/who_am_i/src/frontend/vite.config.js @@ -29,7 +29,7 @@ function getDevServerConfig() { } catch {} throw new Error( - "No local network running. Start with:\n icp network start -d && icp deploy" + "No local network running, or 'backend' is not deployed yet. Run:\n icp network start -d && icp deploy" ); } From 66d629bd6ff6d85d16e25faf26b32c40a0073aac Mon Sep 17 00:00:00 2001 From: Marco Walz Date: Thu, 27 Aug 2026 13:13:34 +0200 Subject: [PATCH 4/6] refactor: one dev-server preflight shape across all 23 vite configs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Follow-on from the error-message fix: rewording the message papered over a structural problem. Two distinct failure causes shared one try/catch, so no wording could be accurate. hello_world's shape was closer but not correct either. It splits the canister lookup into its own try/catch with a precise message, but leaves `icp network status` unguarded — a down network there surfaces a raw "Command failed: icp network status ..." plus a vite stack instead of a remedy. It also reads the proxy target from `networkStatus.api_url` rather than hardcoding a port, which the other 15 did not. All 23 dev-server configs now do the same two-step preflight, each step guarded separately and each failing with its own message and exit 1: No local network running. Start it and deploy first: icp network start -d && icp deploy Canister 'backend' is not deployed on the local network. Deploy it first: icp deploy backend Both `execSync` calls take `stdio: "pipe"` so the raw CLI error is suppressed and only the actionable message is shown. The proxy target is now `networkStatus.api_url` everywhere, replacing the hardcoded `http://127.0.0.1:8000` in 15 configs. That was not merely cosmetic: on a project configured for another port (or `port: 0` for parallel worktrees) the dev server was silently proxying to whatever happened to be on 8000 — possibly a different project's network. `replicaPort` in filevault and both who_am_i is likewise derived from `api_url` instead of the "8000" literal, so the Internet Identity URL they build is right on any port. Verified end-to-end on rust/qrcode against a network on port 8125: 1. no network → network message, no stack, no raw CLI error 2. network up, no deploy → deploy message (the case Copilot flagged) 3. deployed → dev server starts; GET /api/v2/status through the proxy returns byte-identical output to a direct call on 8125, confirming it follows api_url rather than 8000 All 23 files parse; every one has both guards and none hardcodes a port. Co-Authored-By: Claude Opus 5 (1M context) --- motoko/cert-var/frontend/vite.config.js | 54 +++++++++++------- motoko/daily_planner/frontend/vite.config.js | 54 +++++++++++------- .../frontend/vite.config.js | 31 ++++++---- motoko/filevault/frontend/vite.config.js | 56 ++++++++++++------- motoko/flying_ninja/frontend/vite.config.js | 55 +++++++++++------- motoko/hello_world/frontend/vite.config.js | 33 ++++++----- motoko/llm_chatbot/frontend/vite.config.js | 33 ++++++----- motoko/random_maze/frontend/vite.config.js | 54 +++++++++++------- motoko/superheroes/frontend/vite.config.js | 55 +++++++++++------- .../basic_vetkd/frontend/vite.config.js | 54 +++++++++++------- .../frontend/vite.config.js | 54 +++++++++++------- motoko/who_am_i/src/frontend/vite.config.js | 56 ++++++++++++------- rust/daily_planner/frontend/vite.config.js | 54 +++++++++++------- .../frontend/vite.config.js | 31 ++++++---- rust/face-recognition/frontend/vite.config.js | 33 ++++++----- rust/flying_ninja/frontend/vite.config.js | 54 +++++++++++------- rust/hello_world/frontend/vite.config.js | 33 ++++++----- .../frontend/vite.config.js | 33 ++++++----- rust/llm_chatbot/frontend/vite.config.js | 33 ++++++----- rust/qrcode/frontend/vite.config.js | 54 +++++++++++------- .../basic_vetkd/frontend/vite.config.js | 54 +++++++++++------- .../frontend/vite.config.js | 54 +++++++++++------- rust/who_am_i/src/frontend/vite.config.js | 56 ++++++++++++------- 23 files changed, 673 insertions(+), 405 deletions(-) diff --git a/motoko/cert-var/frontend/vite.config.js b/motoko/cert-var/frontend/vite.config.js index 28522e1aae..6c94031262 100644 --- a/motoko/cert-var/frontend/vite.config.js +++ b/motoko/cert-var/frontend/vite.config.js @@ -3,32 +3,46 @@ import { execSync } from "child_process"; import { icpBindgen } from "@icp-sdk/bindgen/plugins/vite"; function getDevServerConfig() { + let networkStatus; try { - const canisterId = execSync("icp canister status backend -e local -i", { - encoding: "utf-8", - stdio: "pipe", - }).trim(); - const networkStatus = JSON.parse( - execSync("icp network status --json", { + networkStatus = JSON.parse( + execSync("icp network status -e local --json", { encoding: "utf-8", stdio: "pipe", }) ); - return { - headers: { - "Set-Cookie": `ic_env=${encodeURIComponent( - `ic_root_key=${networkStatus.root_key}&PUBLIC_CANISTER_ID:backend=${canisterId}` - )}; SameSite=Lax;`, - }, - proxy: { - "/api": { target: "http://127.0.0.1:8000", changeOrigin: true }, - }, - }; - } catch {} + } catch { + console.error( + "No local network running. Start it and deploy first:\n" + + " icp network start -d && icp deploy" + ); + process.exit(1); + } + + let canisterId; + try { + canisterId = execSync("icp canister status backend -e local -i", { + encoding: "utf-8", + stdio: "pipe", + }).trim(); + } catch { + console.error( + "Canister 'backend' is not deployed on the local network. Deploy it first:\n" + + " icp deploy backend" + ); + process.exit(1); + } - throw new Error( - "No local network running, or 'backend' is not deployed yet. Run:\n icp network start -d && icp deploy" - ); + return { + headers: { + "Set-Cookie": `ic_env=${encodeURIComponent( + `ic_root_key=${networkStatus.root_key}&PUBLIC_CANISTER_ID:backend=${canisterId}` + )}; SameSite=Lax;`, + }, + proxy: { + "/api": { target: networkStatus.api_url, changeOrigin: true }, + }, + }; } export default defineConfig(({ command }) => { diff --git a/motoko/daily_planner/frontend/vite.config.js b/motoko/daily_planner/frontend/vite.config.js index 2f8cc83937..30cf450b32 100644 --- a/motoko/daily_planner/frontend/vite.config.js +++ b/motoko/daily_planner/frontend/vite.config.js @@ -4,32 +4,46 @@ import react from "@vitejs/plugin-react"; import { icpBindgen } from "@icp-sdk/bindgen/plugins/vite"; function getDevServerConfig() { + let networkStatus; try { - const canisterId = execSync("icp canister status backend -e local -i", { - encoding: "utf-8", - stdio: "pipe", - }).trim(); - const networkStatus = JSON.parse( - execSync("icp network status --json", { + networkStatus = JSON.parse( + execSync("icp network status -e local --json", { encoding: "utf-8", stdio: "pipe", }) ); - return { - headers: { - "Set-Cookie": `ic_env=${encodeURIComponent( - `ic_root_key=${networkStatus.root_key}&PUBLIC_CANISTER_ID:backend=${canisterId}` - )}; SameSite=Lax;`, - }, - proxy: { - "/api": { target: "http://127.0.0.1:8000", changeOrigin: true }, - }, - }; - } catch {} + } catch { + console.error( + "No local network running. Start it and deploy first:\n" + + " icp network start -d && icp deploy" + ); + process.exit(1); + } + + let canisterId; + try { + canisterId = execSync("icp canister status backend -e local -i", { + encoding: "utf-8", + stdio: "pipe", + }).trim(); + } catch { + console.error( + "Canister 'backend' is not deployed on the local network. Deploy it first:\n" + + " icp deploy backend" + ); + process.exit(1); + } - throw new Error( - "No local network running, or 'backend' is not deployed yet. Run:\n icp network start -d && icp deploy" - ); + return { + headers: { + "Set-Cookie": `ic_env=${encodeURIComponent( + `ic_root_key=${networkStatus.root_key}&PUBLIC_CANISTER_ID:backend=${canisterId}` + )}; SameSite=Lax;`, + }, + proxy: { + "/api": { target: networkStatus.api_url, changeOrigin: true }, + }, + }; } export default defineConfig(({ command }) => { diff --git a/motoko/evm_block_explorer/frontend/vite.config.js b/motoko/evm_block_explorer/frontend/vite.config.js index faf4c2b869..acdade00c4 100644 --- a/motoko/evm_block_explorer/frontend/vite.config.js +++ b/motoko/evm_block_explorer/frontend/vite.config.js @@ -19,9 +19,21 @@ export default defineConfig(({ command }) => { const environment = process.env.ICP_ENVIRONMENT || "local"; const CANISTER_NAME = "backend"; - const networkStatus = JSON.parse( - execSync(`icp network status -e ${environment} --json`, { encoding: "utf-8" }) - ); + let networkStatus; + try { + networkStatus = JSON.parse( + execSync(`icp network status -e ${environment} --json`, { + encoding: "utf-8", + stdio: "pipe", + }) + ); + } catch { + console.error( + `No local network running for environment "${environment}". Start it and deploy first:\n` + + " icp network start -d && icp deploy" + ); + process.exit(1); + } const rootKey = networkStatus.root_key; const proxyTarget = networkStatus.api_url; @@ -29,16 +41,13 @@ export default defineConfig(({ command }) => { try { canisterId = execSync( `icp canister status ${CANISTER_NAME} -e ${environment} -i`, - { encoding: "utf-8" } + { encoding: "utf-8", stdio: "pipe" } ).trim(); } catch { - console.error(` - Backend canister "${CANISTER_NAME}" not found in environment "${environment}" - - Before running the dev server, deploy the backend canister: - - icp deploy ${CANISTER_NAME} -e ${environment} - `); + console.error( + `Canister "${CANISTER_NAME}" is not deployed in environment "${environment}". Deploy it first:\n` + + ` icp deploy ${CANISTER_NAME} -e ${environment}` + ); process.exit(1); } diff --git a/motoko/filevault/frontend/vite.config.js b/motoko/filevault/frontend/vite.config.js index ca525f7b20..7e3ea289d4 100644 --- a/motoko/filevault/frontend/vite.config.js +++ b/motoko/filevault/frontend/vite.config.js @@ -4,33 +4,47 @@ import react from "@vitejs/plugin-react"; import { icpBindgen } from "@icp-sdk/bindgen/plugins/vite"; function getDevServerConfig() { + let networkStatus; try { - const canisterId = execSync("icp canister status backend -e local -i", { - encoding: "utf-8", - stdio: "pipe", - }).trim(); - const networkStatus = JSON.parse( - execSync("icp network status --json", { + networkStatus = JSON.parse( + execSync("icp network status -e local --json", { encoding: "utf-8", stdio: "pipe", }) ); - return { - replicaPort: "8000", - headers: { - "Set-Cookie": `ic_env=${encodeURIComponent( - `ic_root_key=${networkStatus.root_key}&PUBLIC_CANISTER_ID:backend=${canisterId}` - )}; SameSite=Lax;`, - }, - proxy: { - "/api": { target: "http://127.0.0.1:8000", changeOrigin: true }, - }, - }; - } catch {} + } catch { + console.error( + "No local network running. Start it and deploy first:\n" + + " icp network start -d && icp deploy" + ); + process.exit(1); + } + + let canisterId; + try { + canisterId = execSync("icp canister status backend -e local -i", { + encoding: "utf-8", + stdio: "pipe", + }).trim(); + } catch { + console.error( + "Canister 'backend' is not deployed on the local network. Deploy it first:\n" + + " icp deploy backend" + ); + process.exit(1); + } - throw new Error( - "No local network running, or 'backend' is not deployed yet. Run:\n icp network start -d && icp deploy" - ); + return { + replicaPort: new URL(networkStatus.api_url).port, + headers: { + "Set-Cookie": `ic_env=${encodeURIComponent( + `ic_root_key=${networkStatus.root_key}&PUBLIC_CANISTER_ID:backend=${canisterId}` + )}; SameSite=Lax;`, + }, + proxy: { + "/api": { target: networkStatus.api_url, changeOrigin: true }, + }, + }; } export default defineConfig(({ command }) => { diff --git a/motoko/flying_ninja/frontend/vite.config.js b/motoko/flying_ninja/frontend/vite.config.js index 07b4f0c2dd..1452722fab 100644 --- a/motoko/flying_ninja/frontend/vite.config.js +++ b/motoko/flying_ninja/frontend/vite.config.js @@ -4,33 +4,46 @@ import { execSync } from "child_process"; import { icpBindgen } from "@icp-sdk/bindgen/plugins/vite"; function getDevServerConfig() { - // Try icp-cli first + let networkStatus; try { - const canisterId = execSync("icp canister status backend -e local -i", { - encoding: "utf-8", - stdio: "pipe", - }).trim(); - const networkStatus = JSON.parse( - execSync("icp network status --json", { + networkStatus = JSON.parse( + execSync("icp network status -e local --json", { encoding: "utf-8", stdio: "pipe", }) ); - return { - headers: { - "Set-Cookie": `ic_env=${encodeURIComponent( - `ic_root_key=${networkStatus.root_key}&PUBLIC_CANISTER_ID:backend=${canisterId}` - )}; SameSite=Lax;`, - }, - proxy: { - "/api": { target: "http://127.0.0.1:8000", changeOrigin: true }, - }, - }; - } catch {} + } catch { + console.error( + "No local network running. Start it and deploy first:\n" + + " icp network start -d && icp deploy" + ); + process.exit(1); + } + + let canisterId; + try { + canisterId = execSync("icp canister status backend -e local -i", { + encoding: "utf-8", + stdio: "pipe", + }).trim(); + } catch { + console.error( + "Canister 'backend' is not deployed on the local network. Deploy it first:\n" + + " icp deploy backend" + ); + process.exit(1); + } - throw new Error( - "No local network running, or 'backend' is not deployed yet. Run:\n icp network start -d && icp deploy" - ); + return { + headers: { + "Set-Cookie": `ic_env=${encodeURIComponent( + `ic_root_key=${networkStatus.root_key}&PUBLIC_CANISTER_ID:backend=${canisterId}` + )}; SameSite=Lax;`, + }, + proxy: { + "/api": { target: networkStatus.api_url, changeOrigin: true }, + }, + }; } export default defineConfig(({ command }) => { diff --git a/motoko/hello_world/frontend/vite.config.js b/motoko/hello_world/frontend/vite.config.js index d804fa696d..82270e59da 100644 --- a/motoko/hello_world/frontend/vite.config.js +++ b/motoko/hello_world/frontend/vite.config.js @@ -20,11 +20,21 @@ export default defineConfig(({ command }) => { const environment = process.env.ICP_ENVIRONMENT || "local"; const CANISTER_NAME = "backend"; - const networkStatus = JSON.parse( - execSync(`icp network status -e ${environment} --json`, { - encoding: "utf-8", - }) - ); + let networkStatus; + try { + networkStatus = JSON.parse( + execSync(`icp network status -e ${environment} --json`, { + encoding: "utf-8", + stdio: "pipe", + }) + ); + } catch { + console.error( + `No local network running for environment "${environment}". Start it and deploy first:\n` + + " icp network start -d && icp deploy" + ); + process.exit(1); + } const rootKey = networkStatus.root_key; const proxyTarget = networkStatus.api_url; @@ -33,16 +43,13 @@ export default defineConfig(({ command }) => { try { canisterId = execSync( `icp canister status ${CANISTER_NAME} -e ${environment} -i`, - { encoding: "utf-8" } + { encoding: "utf-8", stdio: "pipe" } ).trim(); } catch { - console.error(` - Backend canister "${CANISTER_NAME}" not found in environment "${environment}" - - Before running the dev server, deploy the backend canister: - - icp deploy ${CANISTER_NAME} -e ${environment} - `); + console.error( + `Canister "${CANISTER_NAME}" is not deployed in environment "${environment}". Deploy it first:\n` + + ` icp deploy ${CANISTER_NAME} -e ${environment}` + ); process.exit(1); } diff --git a/motoko/llm_chatbot/frontend/vite.config.js b/motoko/llm_chatbot/frontend/vite.config.js index be7ec53902..96eb839a8b 100644 --- a/motoko/llm_chatbot/frontend/vite.config.js +++ b/motoko/llm_chatbot/frontend/vite.config.js @@ -21,11 +21,21 @@ export default defineConfig(({ command }) => { const environment = process.env.ICP_ENVIRONMENT || "local"; const CANISTER_NAME = "backend"; - const networkStatus = JSON.parse( - execSync(`icp network status -e ${environment} --json`, { - encoding: "utf-8", - }) - ); + let networkStatus; + try { + networkStatus = JSON.parse( + execSync(`icp network status -e ${environment} --json`, { + encoding: "utf-8", + stdio: "pipe", + }) + ); + } catch { + console.error( + `No local network running for environment "${environment}". Start it and deploy first:\n` + + " icp network start -d && icp deploy" + ); + process.exit(1); + } const rootKey = networkStatus.root_key; const proxyTarget = networkStatus.api_url; @@ -33,16 +43,13 @@ export default defineConfig(({ command }) => { try { canisterId = execSync( `icp canister status ${CANISTER_NAME} -e ${environment} -i`, - { encoding: "utf-8" } + { encoding: "utf-8", stdio: "pipe" } ).trim(); } catch { - console.error(` - Backend canister "${CANISTER_NAME}" not found in environment "${environment}" - - Before running the dev server, deploy the backend canister: - - icp deploy ${CANISTER_NAME} -e ${environment} - `); + console.error( + `Canister "${CANISTER_NAME}" is not deployed in environment "${environment}". Deploy it first:\n` + + ` icp deploy ${CANISTER_NAME} -e ${environment}` + ); process.exit(1); } diff --git a/motoko/random_maze/frontend/vite.config.js b/motoko/random_maze/frontend/vite.config.js index 2f8cc83937..30cf450b32 100644 --- a/motoko/random_maze/frontend/vite.config.js +++ b/motoko/random_maze/frontend/vite.config.js @@ -4,32 +4,46 @@ import react from "@vitejs/plugin-react"; import { icpBindgen } from "@icp-sdk/bindgen/plugins/vite"; function getDevServerConfig() { + let networkStatus; try { - const canisterId = execSync("icp canister status backend -e local -i", { - encoding: "utf-8", - stdio: "pipe", - }).trim(); - const networkStatus = JSON.parse( - execSync("icp network status --json", { + networkStatus = JSON.parse( + execSync("icp network status -e local --json", { encoding: "utf-8", stdio: "pipe", }) ); - return { - headers: { - "Set-Cookie": `ic_env=${encodeURIComponent( - `ic_root_key=${networkStatus.root_key}&PUBLIC_CANISTER_ID:backend=${canisterId}` - )}; SameSite=Lax;`, - }, - proxy: { - "/api": { target: "http://127.0.0.1:8000", changeOrigin: true }, - }, - }; - } catch {} + } catch { + console.error( + "No local network running. Start it and deploy first:\n" + + " icp network start -d && icp deploy" + ); + process.exit(1); + } + + let canisterId; + try { + canisterId = execSync("icp canister status backend -e local -i", { + encoding: "utf-8", + stdio: "pipe", + }).trim(); + } catch { + console.error( + "Canister 'backend' is not deployed on the local network. Deploy it first:\n" + + " icp deploy backend" + ); + process.exit(1); + } - throw new Error( - "No local network running, or 'backend' is not deployed yet. Run:\n icp network start -d && icp deploy" - ); + return { + headers: { + "Set-Cookie": `ic_env=${encodeURIComponent( + `ic_root_key=${networkStatus.root_key}&PUBLIC_CANISTER_ID:backend=${canisterId}` + )}; SameSite=Lax;`, + }, + proxy: { + "/api": { target: networkStatus.api_url, changeOrigin: true }, + }, + }; } export default defineConfig(({ command }) => { diff --git a/motoko/superheroes/frontend/vite.config.js b/motoko/superheroes/frontend/vite.config.js index 290fd63251..74a6c06631 100644 --- a/motoko/superheroes/frontend/vite.config.js +++ b/motoko/superheroes/frontend/vite.config.js @@ -4,33 +4,46 @@ import { icpBindgen } from "@icp-sdk/bindgen/plugins/vite"; import react from "@vitejs/plugin-react"; function getDevServerConfig() { - // Try icp-cli first + let networkStatus; try { - const canisterId = execSync("icp canister status backend -e local -i", { - encoding: "utf-8", - stdio: "pipe", - }).trim(); - const networkStatus = JSON.parse( - execSync("icp network status --json", { + networkStatus = JSON.parse( + execSync("icp network status -e local --json", { encoding: "utf-8", stdio: "pipe", }) ); - return { - headers: { - "Set-Cookie": `ic_env=${encodeURIComponent( - `ic_root_key=${networkStatus.root_key}&PUBLIC_CANISTER_ID:backend=${canisterId}` - )}; SameSite=Lax;`, - }, - proxy: { - "/api": { target: "http://127.0.0.1:8000", changeOrigin: true }, - }, - }; - } catch {} + } catch { + console.error( + "No local network running. Start it and deploy first:\n" + + " icp network start -d && icp deploy" + ); + process.exit(1); + } + + let canisterId; + try { + canisterId = execSync("icp canister status backend -e local -i", { + encoding: "utf-8", + stdio: "pipe", + }).trim(); + } catch { + console.error( + "Canister 'backend' is not deployed on the local network. Deploy it first:\n" + + " icp deploy backend" + ); + process.exit(1); + } - throw new Error( - "No local network running, or 'backend' is not deployed yet. Run:\n icp network start -d && icp deploy" - ); + return { + headers: { + "Set-Cookie": `ic_env=${encodeURIComponent( + `ic_root_key=${networkStatus.root_key}&PUBLIC_CANISTER_ID:backend=${canisterId}` + )}; SameSite=Lax;`, + }, + proxy: { + "/api": { target: networkStatus.api_url, changeOrigin: true }, + }, + }; } export default defineConfig(({ command }) => { diff --git a/motoko/vetkeys/basic_vetkd/frontend/vite.config.js b/motoko/vetkeys/basic_vetkd/frontend/vite.config.js index b0a8fe5d5f..07fd35b1f4 100644 --- a/motoko/vetkeys/basic_vetkd/frontend/vite.config.js +++ b/motoko/vetkeys/basic_vetkd/frontend/vite.config.js @@ -3,32 +3,46 @@ import { execSync } from "child_process"; import { icpBindgen } from "@icp-sdk/bindgen/plugins/vite"; function getDevServerConfig() { + let networkStatus; try { - const canisterId = execSync("icp canister status backend -e local -i", { - encoding: "utf-8", - stdio: "pipe", - }).trim(); - const networkStatus = JSON.parse( - execSync("icp network status --json", { + networkStatus = JSON.parse( + execSync("icp network status -e local --json", { encoding: "utf-8", stdio: "pipe", }) ); - return { - headers: { - "Set-Cookie": `ic_env=${encodeURIComponent( - `ic_root_key=${networkStatus.root_key}&PUBLIC_CANISTER_ID:backend=${canisterId}` - )}; SameSite=Lax;`, - }, - proxy: { - "/api": { target: "http://127.0.0.1:8000", changeOrigin: true }, - }, - }; - } catch {} + } catch { + console.error( + "No local network running. Start it and deploy first:\n" + + " icp network start -d && icp deploy" + ); + process.exit(1); + } + + let canisterId; + try { + canisterId = execSync("icp canister status backend -e local -i", { + encoding: "utf-8", + stdio: "pipe", + }).trim(); + } catch { + console.error( + "Canister 'backend' is not deployed on the local network. Deploy it first:\n" + + " icp deploy backend" + ); + process.exit(1); + } - throw new Error( - "No local network running, or 'backend' is not deployed yet. Run:\n icp network start -d && icp deploy" - ); + return { + headers: { + "Set-Cookie": `ic_env=${encodeURIComponent( + `ic_root_key=${networkStatus.root_key}&PUBLIC_CANISTER_ID:backend=${canisterId}` + )}; SameSite=Lax;`, + }, + proxy: { + "/api": { target: networkStatus.api_url, changeOrigin: true }, + }, + }; } export default defineConfig(({ command }) => ({ diff --git a/motoko/vetkeys/password_manager_with_metadata/frontend/vite.config.js b/motoko/vetkeys/password_manager_with_metadata/frontend/vite.config.js index 531175c7c3..25eb541f58 100644 --- a/motoko/vetkeys/password_manager_with_metadata/frontend/vite.config.js +++ b/motoko/vetkeys/password_manager_with_metadata/frontend/vite.config.js @@ -7,32 +7,46 @@ import { icpBindgen } from "@icp-sdk/bindgen/plugins/vite"; import { execSync } from "child_process"; function getDevServerConfig() { + let networkStatus; try { - const canisterId = execSync("icp canister status backend -e local -i", { - encoding: "utf-8", - stdio: "pipe", - }).trim(); - const networkStatus = JSON.parse( - execSync("icp network status --json", { + networkStatus = JSON.parse( + execSync("icp network status -e local --json", { encoding: "utf-8", stdio: "pipe", }) ); - return { - headers: { - "Set-Cookie": `ic_env=${encodeURIComponent( - `ic_root_key=${networkStatus.root_key}&PUBLIC_CANISTER_ID:backend=${canisterId}` - )}; SameSite=Lax;`, - }, - proxy: { - "/api": { target: "http://127.0.0.1:8000", changeOrigin: true }, - }, - }; - } catch {} + } catch { + console.error( + "No local network running. Start it and deploy first:\n" + + " icp network start -d && icp deploy" + ); + process.exit(1); + } + + let canisterId; + try { + canisterId = execSync("icp canister status backend -e local -i", { + encoding: "utf-8", + stdio: "pipe", + }).trim(); + } catch { + console.error( + "Canister 'backend' is not deployed on the local network. Deploy it first:\n" + + " icp deploy backend" + ); + process.exit(1); + } - throw new Error( - "No local network running, or 'backend' is not deployed yet. Run:\n icp network start -d && icp deploy" - ); + return { + headers: { + "Set-Cookie": `ic_env=${encodeURIComponent( + `ic_root_key=${networkStatus.root_key}&PUBLIC_CANISTER_ID:backend=${canisterId}` + )}; SameSite=Lax;`, + }, + proxy: { + "/api": { target: networkStatus.api_url, changeOrigin: true }, + }, + }; } export default defineConfig(({ command }) => ({ diff --git a/motoko/who_am_i/src/frontend/vite.config.js b/motoko/who_am_i/src/frontend/vite.config.js index ca525f7b20..7e3ea289d4 100644 --- a/motoko/who_am_i/src/frontend/vite.config.js +++ b/motoko/who_am_i/src/frontend/vite.config.js @@ -4,33 +4,47 @@ import react from "@vitejs/plugin-react"; import { icpBindgen } from "@icp-sdk/bindgen/plugins/vite"; function getDevServerConfig() { + let networkStatus; try { - const canisterId = execSync("icp canister status backend -e local -i", { - encoding: "utf-8", - stdio: "pipe", - }).trim(); - const networkStatus = JSON.parse( - execSync("icp network status --json", { + networkStatus = JSON.parse( + execSync("icp network status -e local --json", { encoding: "utf-8", stdio: "pipe", }) ); - return { - replicaPort: "8000", - headers: { - "Set-Cookie": `ic_env=${encodeURIComponent( - `ic_root_key=${networkStatus.root_key}&PUBLIC_CANISTER_ID:backend=${canisterId}` - )}; SameSite=Lax;`, - }, - proxy: { - "/api": { target: "http://127.0.0.1:8000", changeOrigin: true }, - }, - }; - } catch {} + } catch { + console.error( + "No local network running. Start it and deploy first:\n" + + " icp network start -d && icp deploy" + ); + process.exit(1); + } + + let canisterId; + try { + canisterId = execSync("icp canister status backend -e local -i", { + encoding: "utf-8", + stdio: "pipe", + }).trim(); + } catch { + console.error( + "Canister 'backend' is not deployed on the local network. Deploy it first:\n" + + " icp deploy backend" + ); + process.exit(1); + } - throw new Error( - "No local network running, or 'backend' is not deployed yet. Run:\n icp network start -d && icp deploy" - ); + return { + replicaPort: new URL(networkStatus.api_url).port, + headers: { + "Set-Cookie": `ic_env=${encodeURIComponent( + `ic_root_key=${networkStatus.root_key}&PUBLIC_CANISTER_ID:backend=${canisterId}` + )}; SameSite=Lax;`, + }, + proxy: { + "/api": { target: networkStatus.api_url, changeOrigin: true }, + }, + }; } export default defineConfig(({ command }) => { diff --git a/rust/daily_planner/frontend/vite.config.js b/rust/daily_planner/frontend/vite.config.js index 2f8cc83937..30cf450b32 100644 --- a/rust/daily_planner/frontend/vite.config.js +++ b/rust/daily_planner/frontend/vite.config.js @@ -4,32 +4,46 @@ import react from "@vitejs/plugin-react"; import { icpBindgen } from "@icp-sdk/bindgen/plugins/vite"; function getDevServerConfig() { + let networkStatus; try { - const canisterId = execSync("icp canister status backend -e local -i", { - encoding: "utf-8", - stdio: "pipe", - }).trim(); - const networkStatus = JSON.parse( - execSync("icp network status --json", { + networkStatus = JSON.parse( + execSync("icp network status -e local --json", { encoding: "utf-8", stdio: "pipe", }) ); - return { - headers: { - "Set-Cookie": `ic_env=${encodeURIComponent( - `ic_root_key=${networkStatus.root_key}&PUBLIC_CANISTER_ID:backend=${canisterId}` - )}; SameSite=Lax;`, - }, - proxy: { - "/api": { target: "http://127.0.0.1:8000", changeOrigin: true }, - }, - }; - } catch {} + } catch { + console.error( + "No local network running. Start it and deploy first:\n" + + " icp network start -d && icp deploy" + ); + process.exit(1); + } + + let canisterId; + try { + canisterId = execSync("icp canister status backend -e local -i", { + encoding: "utf-8", + stdio: "pipe", + }).trim(); + } catch { + console.error( + "Canister 'backend' is not deployed on the local network. Deploy it first:\n" + + " icp deploy backend" + ); + process.exit(1); + } - throw new Error( - "No local network running, or 'backend' is not deployed yet. Run:\n icp network start -d && icp deploy" - ); + return { + headers: { + "Set-Cookie": `ic_env=${encodeURIComponent( + `ic_root_key=${networkStatus.root_key}&PUBLIC_CANISTER_ID:backend=${canisterId}` + )}; SameSite=Lax;`, + }, + proxy: { + "/api": { target: networkStatus.api_url, changeOrigin: true }, + }, + }; } export default defineConfig(({ command }) => { diff --git a/rust/evm_block_explorer/frontend/vite.config.js b/rust/evm_block_explorer/frontend/vite.config.js index faf4c2b869..acdade00c4 100644 --- a/rust/evm_block_explorer/frontend/vite.config.js +++ b/rust/evm_block_explorer/frontend/vite.config.js @@ -19,9 +19,21 @@ export default defineConfig(({ command }) => { const environment = process.env.ICP_ENVIRONMENT || "local"; const CANISTER_NAME = "backend"; - const networkStatus = JSON.parse( - execSync(`icp network status -e ${environment} --json`, { encoding: "utf-8" }) - ); + let networkStatus; + try { + networkStatus = JSON.parse( + execSync(`icp network status -e ${environment} --json`, { + encoding: "utf-8", + stdio: "pipe", + }) + ); + } catch { + console.error( + `No local network running for environment "${environment}". Start it and deploy first:\n` + + " icp network start -d && icp deploy" + ); + process.exit(1); + } const rootKey = networkStatus.root_key; const proxyTarget = networkStatus.api_url; @@ -29,16 +41,13 @@ export default defineConfig(({ command }) => { try { canisterId = execSync( `icp canister status ${CANISTER_NAME} -e ${environment} -i`, - { encoding: "utf-8" } + { encoding: "utf-8", stdio: "pipe" } ).trim(); } catch { - console.error(` - Backend canister "${CANISTER_NAME}" not found in environment "${environment}" - - Before running the dev server, deploy the backend canister: - - icp deploy ${CANISTER_NAME} -e ${environment} - `); + console.error( + `Canister "${CANISTER_NAME}" is not deployed in environment "${environment}". Deploy it first:\n` + + ` icp deploy ${CANISTER_NAME} -e ${environment}` + ); process.exit(1); } diff --git a/rust/face-recognition/frontend/vite.config.js b/rust/face-recognition/frontend/vite.config.js index d804fa696d..82270e59da 100644 --- a/rust/face-recognition/frontend/vite.config.js +++ b/rust/face-recognition/frontend/vite.config.js @@ -20,11 +20,21 @@ export default defineConfig(({ command }) => { const environment = process.env.ICP_ENVIRONMENT || "local"; const CANISTER_NAME = "backend"; - const networkStatus = JSON.parse( - execSync(`icp network status -e ${environment} --json`, { - encoding: "utf-8", - }) - ); + let networkStatus; + try { + networkStatus = JSON.parse( + execSync(`icp network status -e ${environment} --json`, { + encoding: "utf-8", + stdio: "pipe", + }) + ); + } catch { + console.error( + `No local network running for environment "${environment}". Start it and deploy first:\n` + + " icp network start -d && icp deploy" + ); + process.exit(1); + } const rootKey = networkStatus.root_key; const proxyTarget = networkStatus.api_url; @@ -33,16 +43,13 @@ export default defineConfig(({ command }) => { try { canisterId = execSync( `icp canister status ${CANISTER_NAME} -e ${environment} -i`, - { encoding: "utf-8" } + { encoding: "utf-8", stdio: "pipe" } ).trim(); } catch { - console.error(` - Backend canister "${CANISTER_NAME}" not found in environment "${environment}" - - Before running the dev server, deploy the backend canister: - - icp deploy ${CANISTER_NAME} -e ${environment} - `); + console.error( + `Canister "${CANISTER_NAME}" is not deployed in environment "${environment}". Deploy it first:\n` + + ` icp deploy ${CANISTER_NAME} -e ${environment}` + ); process.exit(1); } diff --git a/rust/flying_ninja/frontend/vite.config.js b/rust/flying_ninja/frontend/vite.config.js index c05bb593a2..1452722fab 100644 --- a/rust/flying_ninja/frontend/vite.config.js +++ b/rust/flying_ninja/frontend/vite.config.js @@ -4,32 +4,46 @@ import { execSync } from "child_process"; import { icpBindgen } from "@icp-sdk/bindgen/plugins/vite"; function getDevServerConfig() { + let networkStatus; try { - const canisterId = execSync("icp canister status backend -e local -i", { - encoding: "utf-8", - stdio: "pipe", - }).trim(); - const networkStatus = JSON.parse( - execSync("icp network status --json", { + networkStatus = JSON.parse( + execSync("icp network status -e local --json", { encoding: "utf-8", stdio: "pipe", }) ); - return { - headers: { - "Set-Cookie": `ic_env=${encodeURIComponent( - `ic_root_key=${networkStatus.root_key}&PUBLIC_CANISTER_ID:backend=${canisterId}` - )}; SameSite=Lax;`, - }, - proxy: { - "/api": { target: "http://127.0.0.1:8000", changeOrigin: true }, - }, - }; - } catch {} + } catch { + console.error( + "No local network running. Start it and deploy first:\n" + + " icp network start -d && icp deploy" + ); + process.exit(1); + } + + let canisterId; + try { + canisterId = execSync("icp canister status backend -e local -i", { + encoding: "utf-8", + stdio: "pipe", + }).trim(); + } catch { + console.error( + "Canister 'backend' is not deployed on the local network. Deploy it first:\n" + + " icp deploy backend" + ); + process.exit(1); + } - throw new Error( - "No local network running, or 'backend' is not deployed yet. Run:\n icp network start -d && icp deploy" - ); + return { + headers: { + "Set-Cookie": `ic_env=${encodeURIComponent( + `ic_root_key=${networkStatus.root_key}&PUBLIC_CANISTER_ID:backend=${canisterId}` + )}; SameSite=Lax;`, + }, + proxy: { + "/api": { target: networkStatus.api_url, changeOrigin: true }, + }, + }; } export default defineConfig(({ command }) => { diff --git a/rust/hello_world/frontend/vite.config.js b/rust/hello_world/frontend/vite.config.js index d804fa696d..82270e59da 100644 --- a/rust/hello_world/frontend/vite.config.js +++ b/rust/hello_world/frontend/vite.config.js @@ -20,11 +20,21 @@ export default defineConfig(({ command }) => { const environment = process.env.ICP_ENVIRONMENT || "local"; const CANISTER_NAME = "backend"; - const networkStatus = JSON.parse( - execSync(`icp network status -e ${environment} --json`, { - encoding: "utf-8", - }) - ); + let networkStatus; + try { + networkStatus = JSON.parse( + execSync(`icp network status -e ${environment} --json`, { + encoding: "utf-8", + stdio: "pipe", + }) + ); + } catch { + console.error( + `No local network running for environment "${environment}". Start it and deploy first:\n` + + " icp network start -d && icp deploy" + ); + process.exit(1); + } const rootKey = networkStatus.root_key; const proxyTarget = networkStatus.api_url; @@ -33,16 +43,13 @@ export default defineConfig(({ command }) => { try { canisterId = execSync( `icp canister status ${CANISTER_NAME} -e ${environment} -i`, - { encoding: "utf-8" } + { encoding: "utf-8", stdio: "pipe" } ).trim(); } catch { - console.error(` - Backend canister "${CANISTER_NAME}" not found in environment "${environment}" - - Before running the dev server, deploy the backend canister: - - icp deploy ${CANISTER_NAME} -e ${environment} - `); + console.error( + `Canister "${CANISTER_NAME}" is not deployed in environment "${environment}". Deploy it first:\n` + + ` icp deploy ${CANISTER_NAME} -e ${environment}` + ); process.exit(1); } diff --git a/rust/image-classification/frontend/vite.config.js b/rust/image-classification/frontend/vite.config.js index d804fa696d..82270e59da 100644 --- a/rust/image-classification/frontend/vite.config.js +++ b/rust/image-classification/frontend/vite.config.js @@ -20,11 +20,21 @@ export default defineConfig(({ command }) => { const environment = process.env.ICP_ENVIRONMENT || "local"; const CANISTER_NAME = "backend"; - const networkStatus = JSON.parse( - execSync(`icp network status -e ${environment} --json`, { - encoding: "utf-8", - }) - ); + let networkStatus; + try { + networkStatus = JSON.parse( + execSync(`icp network status -e ${environment} --json`, { + encoding: "utf-8", + stdio: "pipe", + }) + ); + } catch { + console.error( + `No local network running for environment "${environment}". Start it and deploy first:\n` + + " icp network start -d && icp deploy" + ); + process.exit(1); + } const rootKey = networkStatus.root_key; const proxyTarget = networkStatus.api_url; @@ -33,16 +43,13 @@ export default defineConfig(({ command }) => { try { canisterId = execSync( `icp canister status ${CANISTER_NAME} -e ${environment} -i`, - { encoding: "utf-8" } + { encoding: "utf-8", stdio: "pipe" } ).trim(); } catch { - console.error(` - Backend canister "${CANISTER_NAME}" not found in environment "${environment}" - - Before running the dev server, deploy the backend canister: - - icp deploy ${CANISTER_NAME} -e ${environment} - `); + console.error( + `Canister "${CANISTER_NAME}" is not deployed in environment "${environment}". Deploy it first:\n` + + ` icp deploy ${CANISTER_NAME} -e ${environment}` + ); process.exit(1); } diff --git a/rust/llm_chatbot/frontend/vite.config.js b/rust/llm_chatbot/frontend/vite.config.js index be7ec53902..96eb839a8b 100644 --- a/rust/llm_chatbot/frontend/vite.config.js +++ b/rust/llm_chatbot/frontend/vite.config.js @@ -21,11 +21,21 @@ export default defineConfig(({ command }) => { const environment = process.env.ICP_ENVIRONMENT || "local"; const CANISTER_NAME = "backend"; - const networkStatus = JSON.parse( - execSync(`icp network status -e ${environment} --json`, { - encoding: "utf-8", - }) - ); + let networkStatus; + try { + networkStatus = JSON.parse( + execSync(`icp network status -e ${environment} --json`, { + encoding: "utf-8", + stdio: "pipe", + }) + ); + } catch { + console.error( + `No local network running for environment "${environment}". Start it and deploy first:\n` + + " icp network start -d && icp deploy" + ); + process.exit(1); + } const rootKey = networkStatus.root_key; const proxyTarget = networkStatus.api_url; @@ -33,16 +43,13 @@ export default defineConfig(({ command }) => { try { canisterId = execSync( `icp canister status ${CANISTER_NAME} -e ${environment} -i`, - { encoding: "utf-8" } + { encoding: "utf-8", stdio: "pipe" } ).trim(); } catch { - console.error(` - Backend canister "${CANISTER_NAME}" not found in environment "${environment}" - - Before running the dev server, deploy the backend canister: - - icp deploy ${CANISTER_NAME} -e ${environment} - `); + console.error( + `Canister "${CANISTER_NAME}" is not deployed in environment "${environment}". Deploy it first:\n` + + ` icp deploy ${CANISTER_NAME} -e ${environment}` + ); process.exit(1); } diff --git a/rust/qrcode/frontend/vite.config.js b/rust/qrcode/frontend/vite.config.js index 28522e1aae..6c94031262 100644 --- a/rust/qrcode/frontend/vite.config.js +++ b/rust/qrcode/frontend/vite.config.js @@ -3,32 +3,46 @@ import { execSync } from "child_process"; import { icpBindgen } from "@icp-sdk/bindgen/plugins/vite"; function getDevServerConfig() { + let networkStatus; try { - const canisterId = execSync("icp canister status backend -e local -i", { - encoding: "utf-8", - stdio: "pipe", - }).trim(); - const networkStatus = JSON.parse( - execSync("icp network status --json", { + networkStatus = JSON.parse( + execSync("icp network status -e local --json", { encoding: "utf-8", stdio: "pipe", }) ); - return { - headers: { - "Set-Cookie": `ic_env=${encodeURIComponent( - `ic_root_key=${networkStatus.root_key}&PUBLIC_CANISTER_ID:backend=${canisterId}` - )}; SameSite=Lax;`, - }, - proxy: { - "/api": { target: "http://127.0.0.1:8000", changeOrigin: true }, - }, - }; - } catch {} + } catch { + console.error( + "No local network running. Start it and deploy first:\n" + + " icp network start -d && icp deploy" + ); + process.exit(1); + } + + let canisterId; + try { + canisterId = execSync("icp canister status backend -e local -i", { + encoding: "utf-8", + stdio: "pipe", + }).trim(); + } catch { + console.error( + "Canister 'backend' is not deployed on the local network. Deploy it first:\n" + + " icp deploy backend" + ); + process.exit(1); + } - throw new Error( - "No local network running, or 'backend' is not deployed yet. Run:\n icp network start -d && icp deploy" - ); + return { + headers: { + "Set-Cookie": `ic_env=${encodeURIComponent( + `ic_root_key=${networkStatus.root_key}&PUBLIC_CANISTER_ID:backend=${canisterId}` + )}; SameSite=Lax;`, + }, + proxy: { + "/api": { target: networkStatus.api_url, changeOrigin: true }, + }, + }; } export default defineConfig(({ command }) => { diff --git a/rust/vetkeys/basic_vetkd/frontend/vite.config.js b/rust/vetkeys/basic_vetkd/frontend/vite.config.js index b0a8fe5d5f..07fd35b1f4 100644 --- a/rust/vetkeys/basic_vetkd/frontend/vite.config.js +++ b/rust/vetkeys/basic_vetkd/frontend/vite.config.js @@ -3,32 +3,46 @@ import { execSync } from "child_process"; import { icpBindgen } from "@icp-sdk/bindgen/plugins/vite"; function getDevServerConfig() { + let networkStatus; try { - const canisterId = execSync("icp canister status backend -e local -i", { - encoding: "utf-8", - stdio: "pipe", - }).trim(); - const networkStatus = JSON.parse( - execSync("icp network status --json", { + networkStatus = JSON.parse( + execSync("icp network status -e local --json", { encoding: "utf-8", stdio: "pipe", }) ); - return { - headers: { - "Set-Cookie": `ic_env=${encodeURIComponent( - `ic_root_key=${networkStatus.root_key}&PUBLIC_CANISTER_ID:backend=${canisterId}` - )}; SameSite=Lax;`, - }, - proxy: { - "/api": { target: "http://127.0.0.1:8000", changeOrigin: true }, - }, - }; - } catch {} + } catch { + console.error( + "No local network running. Start it and deploy first:\n" + + " icp network start -d && icp deploy" + ); + process.exit(1); + } + + let canisterId; + try { + canisterId = execSync("icp canister status backend -e local -i", { + encoding: "utf-8", + stdio: "pipe", + }).trim(); + } catch { + console.error( + "Canister 'backend' is not deployed on the local network. Deploy it first:\n" + + " icp deploy backend" + ); + process.exit(1); + } - throw new Error( - "No local network running, or 'backend' is not deployed yet. Run:\n icp network start -d && icp deploy" - ); + return { + headers: { + "Set-Cookie": `ic_env=${encodeURIComponent( + `ic_root_key=${networkStatus.root_key}&PUBLIC_CANISTER_ID:backend=${canisterId}` + )}; SameSite=Lax;`, + }, + proxy: { + "/api": { target: networkStatus.api_url, changeOrigin: true }, + }, + }; } export default defineConfig(({ command }) => ({ diff --git a/rust/vetkeys/password_manager_with_metadata/frontend/vite.config.js b/rust/vetkeys/password_manager_with_metadata/frontend/vite.config.js index 531175c7c3..25eb541f58 100644 --- a/rust/vetkeys/password_manager_with_metadata/frontend/vite.config.js +++ b/rust/vetkeys/password_manager_with_metadata/frontend/vite.config.js @@ -7,32 +7,46 @@ import { icpBindgen } from "@icp-sdk/bindgen/plugins/vite"; import { execSync } from "child_process"; function getDevServerConfig() { + let networkStatus; try { - const canisterId = execSync("icp canister status backend -e local -i", { - encoding: "utf-8", - stdio: "pipe", - }).trim(); - const networkStatus = JSON.parse( - execSync("icp network status --json", { + networkStatus = JSON.parse( + execSync("icp network status -e local --json", { encoding: "utf-8", stdio: "pipe", }) ); - return { - headers: { - "Set-Cookie": `ic_env=${encodeURIComponent( - `ic_root_key=${networkStatus.root_key}&PUBLIC_CANISTER_ID:backend=${canisterId}` - )}; SameSite=Lax;`, - }, - proxy: { - "/api": { target: "http://127.0.0.1:8000", changeOrigin: true }, - }, - }; - } catch {} + } catch { + console.error( + "No local network running. Start it and deploy first:\n" + + " icp network start -d && icp deploy" + ); + process.exit(1); + } + + let canisterId; + try { + canisterId = execSync("icp canister status backend -e local -i", { + encoding: "utf-8", + stdio: "pipe", + }).trim(); + } catch { + console.error( + "Canister 'backend' is not deployed on the local network. Deploy it first:\n" + + " icp deploy backend" + ); + process.exit(1); + } - throw new Error( - "No local network running, or 'backend' is not deployed yet. Run:\n icp network start -d && icp deploy" - ); + return { + headers: { + "Set-Cookie": `ic_env=${encodeURIComponent( + `ic_root_key=${networkStatus.root_key}&PUBLIC_CANISTER_ID:backend=${canisterId}` + )}; SameSite=Lax;`, + }, + proxy: { + "/api": { target: networkStatus.api_url, changeOrigin: true }, + }, + }; } export default defineConfig(({ command }) => ({ diff --git a/rust/who_am_i/src/frontend/vite.config.js b/rust/who_am_i/src/frontend/vite.config.js index ca525f7b20..7e3ea289d4 100644 --- a/rust/who_am_i/src/frontend/vite.config.js +++ b/rust/who_am_i/src/frontend/vite.config.js @@ -4,33 +4,47 @@ import react from "@vitejs/plugin-react"; import { icpBindgen } from "@icp-sdk/bindgen/plugins/vite"; function getDevServerConfig() { + let networkStatus; try { - const canisterId = execSync("icp canister status backend -e local -i", { - encoding: "utf-8", - stdio: "pipe", - }).trim(); - const networkStatus = JSON.parse( - execSync("icp network status --json", { + networkStatus = JSON.parse( + execSync("icp network status -e local --json", { encoding: "utf-8", stdio: "pipe", }) ); - return { - replicaPort: "8000", - headers: { - "Set-Cookie": `ic_env=${encodeURIComponent( - `ic_root_key=${networkStatus.root_key}&PUBLIC_CANISTER_ID:backend=${canisterId}` - )}; SameSite=Lax;`, - }, - proxy: { - "/api": { target: "http://127.0.0.1:8000", changeOrigin: true }, - }, - }; - } catch {} + } catch { + console.error( + "No local network running. Start it and deploy first:\n" + + " icp network start -d && icp deploy" + ); + process.exit(1); + } + + let canisterId; + try { + canisterId = execSync("icp canister status backend -e local -i", { + encoding: "utf-8", + stdio: "pipe", + }).trim(); + } catch { + console.error( + "Canister 'backend' is not deployed on the local network. Deploy it first:\n" + + " icp deploy backend" + ); + process.exit(1); + } - throw new Error( - "No local network running, or 'backend' is not deployed yet. Run:\n icp network start -d && icp deploy" - ); + return { + replicaPort: new URL(networkStatus.api_url).port, + headers: { + "Set-Cookie": `ic_env=${encodeURIComponent( + `ic_root_key=${networkStatus.root_key}&PUBLIC_CANISTER_ID:backend=${canisterId}` + )}; SameSite=Lax;`, + }, + proxy: { + "/api": { target: networkStatus.api_url, changeOrigin: true }, + }, + }; } export default defineConfig(({ command }) => { From 1dbefa458f7d4e9340a8bf3444c31dab613aa178 Mon Sep 17 00:00:00 2001 From: Marco Walz Date: Thu, 27 Aug 2026 13:21:09 +0200 Subject: [PATCH 5/6] refactor: make every dev-server config environment-agnostic and identical The previous commit unified error handling but left two shapes behind: 15 configs hardcoded `-e local` and the canister name inline, while the other 8 read `ICP_ENVIRONMENT` and used a `CANISTER_NAME` constant. Only the latter could target anything but the local network. All 23 now share the same two module-level constants and a byte-identical `getDevServerConfig()` (verified: one md5 across all 23, modulo indentation and the optional replicaPort line): const CANISTER_NAME = "backend"; const ENVIRONMENT = process.env.ICP_ENVIRONMENT || "local"; Every `icp` invocation and every message now interpolates them, so the remedy printed is the one that actually applies: Canister "backend" is not deployed in environment "local". Deploy it first: icp deploy backend -e local The 8 inline configs were refactored to call the helper rather than open-code the preflight, so their `defineConfig` bodies collapse to the build early-return plus `server: getDevServerConfig()`. Cookie key order is now uniform too (`ic_root_key` first). No config hardcodes `-e local`, `127.0.0.1:8000`, or a canister name any more. Verified on rust/qrcode (helper group) against a network on port 8126: 1. no network -> environment "local" message 2. ICP_ENVIRONMENT=staging -> environment "staging" message 3. network up, not deployed -> deploy message with `-e local` 4. deployed -> dev server starts; GET /api/v2/status through the proxy is byte-identical to a direct call on 8126 And on rust/hello_world (converted inline group): `npm run build` succeeds without invoking icp, and the dev server prints the network guard. Co-Authored-By: Claude Opus 5 (1M context) --- motoko/cert-var/frontend/vite.config.js | 21 ++--- motoko/daily_planner/frontend/vite.config.js | 21 ++--- .../frontend/vite.config.js | 66 ++++++++-------- motoko/filevault/frontend/vite.config.js | 21 ++--- motoko/flying_ninja/frontend/vite.config.js | 21 ++--- motoko/hello_world/frontend/vite.config.js | 58 ++++++-------- motoko/llm_chatbot/frontend/vite.config.js | 59 +++++++------- motoko/random_maze/frontend/vite.config.js | 21 ++--- motoko/superheroes/frontend/vite.config.js | 21 ++--- .../basic_vetkd/frontend/vite.config.js | 21 ++--- .../frontend/vite.config.js | 79 ++++++++++--------- motoko/who_am_i/src/frontend/vite.config.js | 21 ++--- rust/daily_planner/frontend/vite.config.js | 21 ++--- .../frontend/vite.config.js | 66 ++++++++-------- rust/face-recognition/frontend/vite.config.js | 58 ++++++-------- rust/flying_ninja/frontend/vite.config.js | 21 ++--- rust/hello_world/frontend/vite.config.js | 58 ++++++-------- .../frontend/vite.config.js | 58 ++++++-------- rust/llm_chatbot/frontend/vite.config.js | 59 +++++++------- rust/qrcode/frontend/vite.config.js | 21 ++--- .../basic_vetkd/frontend/vite.config.js | 21 ++--- .../frontend/vite.config.js | 79 ++++++++++--------- rust/who_am_i/src/frontend/vite.config.js | 21 ++--- 23 files changed, 466 insertions(+), 447 deletions(-) diff --git a/motoko/cert-var/frontend/vite.config.js b/motoko/cert-var/frontend/vite.config.js index 6c94031262..26a82aaec9 100644 --- a/motoko/cert-var/frontend/vite.config.js +++ b/motoko/cert-var/frontend/vite.config.js @@ -2,18 +2,21 @@ import { defineConfig } from "vite"; import { execSync } from "child_process"; import { icpBindgen } from "@icp-sdk/bindgen/plugins/vite"; +const CANISTER_NAME = "backend"; +const ENVIRONMENT = process.env.ICP_ENVIRONMENT || "local"; + function getDevServerConfig() { let networkStatus; try { networkStatus = JSON.parse( - execSync("icp network status -e local --json", { + execSync(`icp network status -e ${ENVIRONMENT} --json`, { encoding: "utf-8", stdio: "pipe", }) ); } catch { console.error( - "No local network running. Start it and deploy first:\n" + + `No network running for environment "${ENVIRONMENT}". Start it and deploy first:\n` + " icp network start -d && icp deploy" ); process.exit(1); @@ -21,14 +24,14 @@ function getDevServerConfig() { let canisterId; try { - canisterId = execSync("icp canister status backend -e local -i", { - encoding: "utf-8", - stdio: "pipe", - }).trim(); + canisterId = execSync( + `icp canister status ${CANISTER_NAME} -e ${ENVIRONMENT} -i`, + { encoding: "utf-8", stdio: "pipe" } + ).trim(); } catch { console.error( - "Canister 'backend' is not deployed on the local network. Deploy it first:\n" + - " icp deploy backend" + `Canister "${CANISTER_NAME}" is not deployed in environment "${ENVIRONMENT}". Deploy it first:\n` + + ` icp deploy ${CANISTER_NAME} -e ${ENVIRONMENT}` ); process.exit(1); } @@ -36,7 +39,7 @@ function getDevServerConfig() { return { headers: { "Set-Cookie": `ic_env=${encodeURIComponent( - `ic_root_key=${networkStatus.root_key}&PUBLIC_CANISTER_ID:backend=${canisterId}` + `ic_root_key=${networkStatus.root_key}&PUBLIC_CANISTER_ID:${CANISTER_NAME}=${canisterId}` )}; SameSite=Lax;`, }, proxy: { diff --git a/motoko/daily_planner/frontend/vite.config.js b/motoko/daily_planner/frontend/vite.config.js index 30cf450b32..3cabb9b717 100644 --- a/motoko/daily_planner/frontend/vite.config.js +++ b/motoko/daily_planner/frontend/vite.config.js @@ -3,18 +3,21 @@ import { execSync } from "child_process"; import react from "@vitejs/plugin-react"; import { icpBindgen } from "@icp-sdk/bindgen/plugins/vite"; +const CANISTER_NAME = "backend"; +const ENVIRONMENT = process.env.ICP_ENVIRONMENT || "local"; + function getDevServerConfig() { let networkStatus; try { networkStatus = JSON.parse( - execSync("icp network status -e local --json", { + execSync(`icp network status -e ${ENVIRONMENT} --json`, { encoding: "utf-8", stdio: "pipe", }) ); } catch { console.error( - "No local network running. Start it and deploy first:\n" + + `No network running for environment "${ENVIRONMENT}". Start it and deploy first:\n` + " icp network start -d && icp deploy" ); process.exit(1); @@ -22,14 +25,14 @@ function getDevServerConfig() { let canisterId; try { - canisterId = execSync("icp canister status backend -e local -i", { - encoding: "utf-8", - stdio: "pipe", - }).trim(); + canisterId = execSync( + `icp canister status ${CANISTER_NAME} -e ${ENVIRONMENT} -i`, + { encoding: "utf-8", stdio: "pipe" } + ).trim(); } catch { console.error( - "Canister 'backend' is not deployed on the local network. Deploy it first:\n" + - " icp deploy backend" + `Canister "${CANISTER_NAME}" is not deployed in environment "${ENVIRONMENT}". Deploy it first:\n` + + ` icp deploy ${CANISTER_NAME} -e ${ENVIRONMENT}` ); process.exit(1); } @@ -37,7 +40,7 @@ function getDevServerConfig() { return { headers: { "Set-Cookie": `ic_env=${encodeURIComponent( - `ic_root_key=${networkStatus.root_key}&PUBLIC_CANISTER_ID:backend=${canisterId}` + `ic_root_key=${networkStatus.root_key}&PUBLIC_CANISTER_ID:${CANISTER_NAME}=${canisterId}` )}; SameSite=Lax;`, }, proxy: { diff --git a/motoko/evm_block_explorer/frontend/vite.config.js b/motoko/evm_block_explorer/frontend/vite.config.js index acdade00c4..4e04e937b5 100644 --- a/motoko/evm_block_explorer/frontend/vite.config.js +++ b/motoko/evm_block_explorer/frontend/vite.config.js @@ -3,65 +3,67 @@ import { icpBindgen } from "@icp-sdk/bindgen/plugins/vite"; import react from "@vitejs/plugin-react"; import { execSync } from "child_process"; -export default defineConfig(({ command }) => { - const plugins = [ - react(), - icpBindgen({ - didFile: "../backend/backend.did", - outDir: "./src/bindings", - }), - ]; - - if (command !== "serve") { - return { plugins }; - } - - const environment = process.env.ICP_ENVIRONMENT || "local"; - const CANISTER_NAME = "backend"; +const CANISTER_NAME = "backend"; +const ENVIRONMENT = process.env.ICP_ENVIRONMENT || "local"; +function getDevServerConfig() { let networkStatus; try { networkStatus = JSON.parse( - execSync(`icp network status -e ${environment} --json`, { + execSync(`icp network status -e ${ENVIRONMENT} --json`, { encoding: "utf-8", stdio: "pipe", }) ); } catch { console.error( - `No local network running for environment "${environment}". Start it and deploy first:\n` + + `No network running for environment "${ENVIRONMENT}". Start it and deploy first:\n` + " icp network start -d && icp deploy" ); process.exit(1); } - const rootKey = networkStatus.root_key; - const proxyTarget = networkStatus.api_url; let canisterId; try { canisterId = execSync( - `icp canister status ${CANISTER_NAME} -e ${environment} -i`, + `icp canister status ${CANISTER_NAME} -e ${ENVIRONMENT} -i`, { encoding: "utf-8", stdio: "pipe" } ).trim(); } catch { console.error( - `Canister "${CANISTER_NAME}" is not deployed in environment "${environment}". Deploy it first:\n` + - ` icp deploy ${CANISTER_NAME} -e ${environment}` + `Canister "${CANISTER_NAME}" is not deployed in environment "${ENVIRONMENT}". Deploy it first:\n` + + ` icp deploy ${CANISTER_NAME} -e ${ENVIRONMENT}` ); process.exit(1); } return { - plugins, - server: { - headers: { - "Set-Cookie": `ic_env=${encodeURIComponent( - `PUBLIC_CANISTER_ID:${CANISTER_NAME}=${canisterId}&ic_root_key=${rootKey}` - )}; SameSite=Lax;`, - }, - proxy: { - "/api": { target: proxyTarget, changeOrigin: true }, - }, + headers: { + "Set-Cookie": `ic_env=${encodeURIComponent( + `ic_root_key=${networkStatus.root_key}&PUBLIC_CANISTER_ID:${CANISTER_NAME}=${canisterId}` + )}; SameSite=Lax;`, }, + proxy: { + "/api": { target: networkStatus.api_url, changeOrigin: true }, + }, + }; +} + +export default defineConfig(({ command }) => { + const plugins = [ + react(), + icpBindgen({ + didFile: "../backend/backend.did", + outDir: "./src/bindings", + }), + ]; + + if (command !== "serve") { + return { plugins }; + } + + return { + plugins, + server: getDevServerConfig(), }; }); diff --git a/motoko/filevault/frontend/vite.config.js b/motoko/filevault/frontend/vite.config.js index 7e3ea289d4..0e18d9ab02 100644 --- a/motoko/filevault/frontend/vite.config.js +++ b/motoko/filevault/frontend/vite.config.js @@ -3,18 +3,21 @@ import { execSync } from "child_process"; import react from "@vitejs/plugin-react"; import { icpBindgen } from "@icp-sdk/bindgen/plugins/vite"; +const CANISTER_NAME = "backend"; +const ENVIRONMENT = process.env.ICP_ENVIRONMENT || "local"; + function getDevServerConfig() { let networkStatus; try { networkStatus = JSON.parse( - execSync("icp network status -e local --json", { + execSync(`icp network status -e ${ENVIRONMENT} --json`, { encoding: "utf-8", stdio: "pipe", }) ); } catch { console.error( - "No local network running. Start it and deploy first:\n" + + `No network running for environment "${ENVIRONMENT}". Start it and deploy first:\n` + " icp network start -d && icp deploy" ); process.exit(1); @@ -22,14 +25,14 @@ function getDevServerConfig() { let canisterId; try { - canisterId = execSync("icp canister status backend -e local -i", { - encoding: "utf-8", - stdio: "pipe", - }).trim(); + canisterId = execSync( + `icp canister status ${CANISTER_NAME} -e ${ENVIRONMENT} -i`, + { encoding: "utf-8", stdio: "pipe" } + ).trim(); } catch { console.error( - "Canister 'backend' is not deployed on the local network. Deploy it first:\n" + - " icp deploy backend" + `Canister "${CANISTER_NAME}" is not deployed in environment "${ENVIRONMENT}". Deploy it first:\n` + + ` icp deploy ${CANISTER_NAME} -e ${ENVIRONMENT}` ); process.exit(1); } @@ -38,7 +41,7 @@ function getDevServerConfig() { replicaPort: new URL(networkStatus.api_url).port, headers: { "Set-Cookie": `ic_env=${encodeURIComponent( - `ic_root_key=${networkStatus.root_key}&PUBLIC_CANISTER_ID:backend=${canisterId}` + `ic_root_key=${networkStatus.root_key}&PUBLIC_CANISTER_ID:${CANISTER_NAME}=${canisterId}` )}; SameSite=Lax;`, }, proxy: { diff --git a/motoko/flying_ninja/frontend/vite.config.js b/motoko/flying_ninja/frontend/vite.config.js index 1452722fab..8cc5533817 100644 --- a/motoko/flying_ninja/frontend/vite.config.js +++ b/motoko/flying_ninja/frontend/vite.config.js @@ -3,18 +3,21 @@ import react from "@vitejs/plugin-react"; import { execSync } from "child_process"; import { icpBindgen } from "@icp-sdk/bindgen/plugins/vite"; +const CANISTER_NAME = "backend"; +const ENVIRONMENT = process.env.ICP_ENVIRONMENT || "local"; + function getDevServerConfig() { let networkStatus; try { networkStatus = JSON.parse( - execSync("icp network status -e local --json", { + execSync(`icp network status -e ${ENVIRONMENT} --json`, { encoding: "utf-8", stdio: "pipe", }) ); } catch { console.error( - "No local network running. Start it and deploy first:\n" + + `No network running for environment "${ENVIRONMENT}". Start it and deploy first:\n` + " icp network start -d && icp deploy" ); process.exit(1); @@ -22,14 +25,14 @@ function getDevServerConfig() { let canisterId; try { - canisterId = execSync("icp canister status backend -e local -i", { - encoding: "utf-8", - stdio: "pipe", - }).trim(); + canisterId = execSync( + `icp canister status ${CANISTER_NAME} -e ${ENVIRONMENT} -i`, + { encoding: "utf-8", stdio: "pipe" } + ).trim(); } catch { console.error( - "Canister 'backend' is not deployed on the local network. Deploy it first:\n" + - " icp deploy backend" + `Canister "${CANISTER_NAME}" is not deployed in environment "${ENVIRONMENT}". Deploy it first:\n` + + ` icp deploy ${CANISTER_NAME} -e ${ENVIRONMENT}` ); process.exit(1); } @@ -37,7 +40,7 @@ function getDevServerConfig() { return { headers: { "Set-Cookie": `ic_env=${encodeURIComponent( - `ic_root_key=${networkStatus.root_key}&PUBLIC_CANISTER_ID:backend=${canisterId}` + `ic_root_key=${networkStatus.root_key}&PUBLIC_CANISTER_ID:${CANISTER_NAME}=${canisterId}` )}; SameSite=Lax;`, }, proxy: { diff --git a/motoko/hello_world/frontend/vite.config.js b/motoko/hello_world/frontend/vite.config.js index 82270e59da..b85659cc7f 100644 --- a/motoko/hello_world/frontend/vite.config.js +++ b/motoko/hello_world/frontend/vite.config.js @@ -2,73 +2,67 @@ import { defineConfig } from "vite"; import { icpBindgen } from "@icp-sdk/bindgen/plugins/vite"; import { execSync } from "child_process"; -export default defineConfig(({ command }) => { - const plugins = [ - icpBindgen({ - didFile: "../backend/backend.did", - outDir: "./src/bindings", - }), - ]; - - // If we're only building this is enough - if (command !== "serve") { - return { plugins }; - } - - // If we're running the local npm dev server, we're going to look up the - // local network's root key and the relevant canister ids. - const environment = process.env.ICP_ENVIRONMENT || "local"; - const CANISTER_NAME = "backend"; +const CANISTER_NAME = "backend"; +const ENVIRONMENT = process.env.ICP_ENVIRONMENT || "local"; +function getDevServerConfig() { let networkStatus; try { networkStatus = JSON.parse( - execSync(`icp network status -e ${environment} --json`, { + execSync(`icp network status -e ${ENVIRONMENT} --json`, { encoding: "utf-8", stdio: "pipe", }) ); } catch { console.error( - `No local network running for environment "${environment}". Start it and deploy first:\n` + + `No network running for environment "${ENVIRONMENT}". Start it and deploy first:\n` + " icp network start -d && icp deploy" ); process.exit(1); } - const rootKey = networkStatus.root_key; - const proxyTarget = networkStatus.api_url; - // Backend must be deployed before starting dev server let canisterId; try { canisterId = execSync( - `icp canister status ${CANISTER_NAME} -e ${environment} -i`, + `icp canister status ${CANISTER_NAME} -e ${ENVIRONMENT} -i`, { encoding: "utf-8", stdio: "pipe" } ).trim(); } catch { console.error( - `Canister "${CANISTER_NAME}" is not deployed in environment "${environment}". Deploy it first:\n` + - ` icp deploy ${CANISTER_NAME} -e ${environment}` + `Canister "${CANISTER_NAME}" is not deployed in environment "${ENVIRONMENT}". Deploy it first:\n` + + ` icp deploy ${CANISTER_NAME} -e ${ENVIRONMENT}` ); process.exit(1); } - const server = { + return { headers: { "Set-Cookie": `ic_env=${encodeURIComponent( - `PUBLIC_CANISTER_ID:${CANISTER_NAME}=${canisterId}&ic_root_key=${rootKey}` + `ic_root_key=${networkStatus.root_key}&PUBLIC_CANISTER_ID:${CANISTER_NAME}=${canisterId}` )}; SameSite=Lax;`, }, proxy: { - "/api": { - target: proxyTarget, - changeOrigin: true, - }, + "/api": { target: networkStatus.api_url, changeOrigin: true }, }, }; +} + +export default defineConfig(({ command }) => { + const plugins = [ + icpBindgen({ + didFile: "../backend/backend.did", + outDir: "./src/bindings", + }), + ]; + + // If we're only building this is enough + if (command !== "serve") { + return { plugins }; + } return { plugins, - server, + server: getDevServerConfig(), }; }); diff --git a/motoko/llm_chatbot/frontend/vite.config.js b/motoko/llm_chatbot/frontend/vite.config.js index 96eb839a8b..468af6aaaa 100644 --- a/motoko/llm_chatbot/frontend/vite.config.js +++ b/motoko/llm_chatbot/frontend/vite.config.js @@ -3,72 +3,69 @@ import react from "@vitejs/plugin-react"; import { icpBindgen } from "@icp-sdk/bindgen/plugins/vite"; import { execSync } from "child_process"; -export default defineConfig(({ command }) => { - const plugins = [ - react(), - icpBindgen({ - didFile: "../backend/backend.did", - outDir: "./src/bindings", - }), - ]; - - // Build only — no dev-server setup needed - if (command !== "serve") { - return { plugins }; - } - - // Dev server: look up the local network root key and backend canister ID - const environment = process.env.ICP_ENVIRONMENT || "local"; - const CANISTER_NAME = "backend"; +const CANISTER_NAME = "backend"; +const ENVIRONMENT = process.env.ICP_ENVIRONMENT || "local"; +function getDevServerConfig() { let networkStatus; try { networkStatus = JSON.parse( - execSync(`icp network status -e ${environment} --json`, { + execSync(`icp network status -e ${ENVIRONMENT} --json`, { encoding: "utf-8", stdio: "pipe", }) ); } catch { console.error( - `No local network running for environment "${environment}". Start it and deploy first:\n` + + `No network running for environment "${ENVIRONMENT}". Start it and deploy first:\n` + " icp network start -d && icp deploy" ); process.exit(1); } - const rootKey = networkStatus.root_key; - const proxyTarget = networkStatus.api_url; let canisterId; try { canisterId = execSync( - `icp canister status ${CANISTER_NAME} -e ${environment} -i`, + `icp canister status ${CANISTER_NAME} -e ${ENVIRONMENT} -i`, { encoding: "utf-8", stdio: "pipe" } ).trim(); } catch { console.error( - `Canister "${CANISTER_NAME}" is not deployed in environment "${environment}". Deploy it first:\n` + - ` icp deploy ${CANISTER_NAME} -e ${environment}` + `Canister "${CANISTER_NAME}" is not deployed in environment "${ENVIRONMENT}". Deploy it first:\n` + + ` icp deploy ${CANISTER_NAME} -e ${ENVIRONMENT}` ); process.exit(1); } - const server = { + return { headers: { "Set-Cookie": `ic_env=${encodeURIComponent( - `PUBLIC_CANISTER_ID:${CANISTER_NAME}=${canisterId}&ic_root_key=${rootKey}` + `ic_root_key=${networkStatus.root_key}&PUBLIC_CANISTER_ID:${CANISTER_NAME}=${canisterId}` )}; SameSite=Lax;`, }, proxy: { - "/api": { - target: proxyTarget, - changeOrigin: true, - }, + "/api": { target: networkStatus.api_url, changeOrigin: true }, }, }; +} +export default defineConfig(({ command }) => { + const plugins = [ + react(), + icpBindgen({ + didFile: "../backend/backend.did", + outDir: "./src/bindings", + }), + ]; + + // Build only — no dev-server setup needed + if (command !== "serve") { + return { plugins }; + } + + // Dev server: look up the local network root key and backend canister ID return { plugins, - server, + server: getDevServerConfig(), }; }); diff --git a/motoko/random_maze/frontend/vite.config.js b/motoko/random_maze/frontend/vite.config.js index 30cf450b32..3cabb9b717 100644 --- a/motoko/random_maze/frontend/vite.config.js +++ b/motoko/random_maze/frontend/vite.config.js @@ -3,18 +3,21 @@ import { execSync } from "child_process"; import react from "@vitejs/plugin-react"; import { icpBindgen } from "@icp-sdk/bindgen/plugins/vite"; +const CANISTER_NAME = "backend"; +const ENVIRONMENT = process.env.ICP_ENVIRONMENT || "local"; + function getDevServerConfig() { let networkStatus; try { networkStatus = JSON.parse( - execSync("icp network status -e local --json", { + execSync(`icp network status -e ${ENVIRONMENT} --json`, { encoding: "utf-8", stdio: "pipe", }) ); } catch { console.error( - "No local network running. Start it and deploy first:\n" + + `No network running for environment "${ENVIRONMENT}". Start it and deploy first:\n` + " icp network start -d && icp deploy" ); process.exit(1); @@ -22,14 +25,14 @@ function getDevServerConfig() { let canisterId; try { - canisterId = execSync("icp canister status backend -e local -i", { - encoding: "utf-8", - stdio: "pipe", - }).trim(); + canisterId = execSync( + `icp canister status ${CANISTER_NAME} -e ${ENVIRONMENT} -i`, + { encoding: "utf-8", stdio: "pipe" } + ).trim(); } catch { console.error( - "Canister 'backend' is not deployed on the local network. Deploy it first:\n" + - " icp deploy backend" + `Canister "${CANISTER_NAME}" is not deployed in environment "${ENVIRONMENT}". Deploy it first:\n` + + ` icp deploy ${CANISTER_NAME} -e ${ENVIRONMENT}` ); process.exit(1); } @@ -37,7 +40,7 @@ function getDevServerConfig() { return { headers: { "Set-Cookie": `ic_env=${encodeURIComponent( - `ic_root_key=${networkStatus.root_key}&PUBLIC_CANISTER_ID:backend=${canisterId}` + `ic_root_key=${networkStatus.root_key}&PUBLIC_CANISTER_ID:${CANISTER_NAME}=${canisterId}` )}; SameSite=Lax;`, }, proxy: { diff --git a/motoko/superheroes/frontend/vite.config.js b/motoko/superheroes/frontend/vite.config.js index 74a6c06631..571d590c1a 100644 --- a/motoko/superheroes/frontend/vite.config.js +++ b/motoko/superheroes/frontend/vite.config.js @@ -3,18 +3,21 @@ import { execSync } from "child_process"; import { icpBindgen } from "@icp-sdk/bindgen/plugins/vite"; import react from "@vitejs/plugin-react"; +const CANISTER_NAME = "backend"; +const ENVIRONMENT = process.env.ICP_ENVIRONMENT || "local"; + function getDevServerConfig() { let networkStatus; try { networkStatus = JSON.parse( - execSync("icp network status -e local --json", { + execSync(`icp network status -e ${ENVIRONMENT} --json`, { encoding: "utf-8", stdio: "pipe", }) ); } catch { console.error( - "No local network running. Start it and deploy first:\n" + + `No network running for environment "${ENVIRONMENT}". Start it and deploy first:\n` + " icp network start -d && icp deploy" ); process.exit(1); @@ -22,14 +25,14 @@ function getDevServerConfig() { let canisterId; try { - canisterId = execSync("icp canister status backend -e local -i", { - encoding: "utf-8", - stdio: "pipe", - }).trim(); + canisterId = execSync( + `icp canister status ${CANISTER_NAME} -e ${ENVIRONMENT} -i`, + { encoding: "utf-8", stdio: "pipe" } + ).trim(); } catch { console.error( - "Canister 'backend' is not deployed on the local network. Deploy it first:\n" + - " icp deploy backend" + `Canister "${CANISTER_NAME}" is not deployed in environment "${ENVIRONMENT}". Deploy it first:\n` + + ` icp deploy ${CANISTER_NAME} -e ${ENVIRONMENT}` ); process.exit(1); } @@ -37,7 +40,7 @@ function getDevServerConfig() { return { headers: { "Set-Cookie": `ic_env=${encodeURIComponent( - `ic_root_key=${networkStatus.root_key}&PUBLIC_CANISTER_ID:backend=${canisterId}` + `ic_root_key=${networkStatus.root_key}&PUBLIC_CANISTER_ID:${CANISTER_NAME}=${canisterId}` )}; SameSite=Lax;`, }, proxy: { diff --git a/motoko/vetkeys/basic_vetkd/frontend/vite.config.js b/motoko/vetkeys/basic_vetkd/frontend/vite.config.js index 07fd35b1f4..6fc36eee1b 100644 --- a/motoko/vetkeys/basic_vetkd/frontend/vite.config.js +++ b/motoko/vetkeys/basic_vetkd/frontend/vite.config.js @@ -2,18 +2,21 @@ import { defineConfig } from "vite"; import { execSync } from "child_process"; import { icpBindgen } from "@icp-sdk/bindgen/plugins/vite"; +const CANISTER_NAME = "backend"; +const ENVIRONMENT = process.env.ICP_ENVIRONMENT || "local"; + function getDevServerConfig() { let networkStatus; try { networkStatus = JSON.parse( - execSync("icp network status -e local --json", { + execSync(`icp network status -e ${ENVIRONMENT} --json`, { encoding: "utf-8", stdio: "pipe", }) ); } catch { console.error( - "No local network running. Start it and deploy first:\n" + + `No network running for environment "${ENVIRONMENT}". Start it and deploy first:\n` + " icp network start -d && icp deploy" ); process.exit(1); @@ -21,14 +24,14 @@ function getDevServerConfig() { let canisterId; try { - canisterId = execSync("icp canister status backend -e local -i", { - encoding: "utf-8", - stdio: "pipe", - }).trim(); + canisterId = execSync( + `icp canister status ${CANISTER_NAME} -e ${ENVIRONMENT} -i`, + { encoding: "utf-8", stdio: "pipe" } + ).trim(); } catch { console.error( - "Canister 'backend' is not deployed on the local network. Deploy it first:\n" + - " icp deploy backend" + `Canister "${CANISTER_NAME}" is not deployed in environment "${ENVIRONMENT}". Deploy it first:\n` + + ` icp deploy ${CANISTER_NAME} -e ${ENVIRONMENT}` ); process.exit(1); } @@ -36,7 +39,7 @@ function getDevServerConfig() { return { headers: { "Set-Cookie": `ic_env=${encodeURIComponent( - `ic_root_key=${networkStatus.root_key}&PUBLIC_CANISTER_ID:backend=${canisterId}` + `ic_root_key=${networkStatus.root_key}&PUBLIC_CANISTER_ID:${CANISTER_NAME}=${canisterId}` )}; SameSite=Lax;`, }, proxy: { diff --git a/motoko/vetkeys/password_manager_with_metadata/frontend/vite.config.js b/motoko/vetkeys/password_manager_with_metadata/frontend/vite.config.js index 25eb541f58..a0f092a005 100644 --- a/motoko/vetkeys/password_manager_with_metadata/frontend/vite.config.js +++ b/motoko/vetkeys/password_manager_with_metadata/frontend/vite.config.js @@ -6,47 +6,50 @@ import css from "rollup-plugin-css-only"; import { icpBindgen } from "@icp-sdk/bindgen/plugins/vite"; import { execSync } from "child_process"; +const CANISTER_NAME = "backend"; +const ENVIRONMENT = process.env.ICP_ENVIRONMENT || "local"; + function getDevServerConfig() { - let networkStatus; - try { - networkStatus = JSON.parse( - execSync("icp network status -e local --json", { - encoding: "utf-8", - stdio: "pipe", - }) - ); - } catch { - console.error( - "No local network running. Start it and deploy first:\n" + - " icp network start -d && icp deploy" - ); - process.exit(1); - } + let networkStatus; + try { + networkStatus = JSON.parse( + execSync(`icp network status -e ${ENVIRONMENT} --json`, { + encoding: "utf-8", + stdio: "pipe", + }) + ); + } catch { + console.error( + `No network running for environment "${ENVIRONMENT}". Start it and deploy first:\n` + + " icp network start -d && icp deploy" + ); + process.exit(1); + } - let canisterId; - try { - canisterId = execSync("icp canister status backend -e local -i", { - encoding: "utf-8", - stdio: "pipe", - }).trim(); - } catch { - console.error( - "Canister 'backend' is not deployed on the local network. Deploy it first:\n" + - " icp deploy backend" - ); - process.exit(1); - } + let canisterId; + try { + canisterId = execSync( + `icp canister status ${CANISTER_NAME} -e ${ENVIRONMENT} -i`, + { encoding: "utf-8", stdio: "pipe" } + ).trim(); + } catch { + console.error( + `Canister "${CANISTER_NAME}" is not deployed in environment "${ENVIRONMENT}". Deploy it first:\n` + + ` icp deploy ${CANISTER_NAME} -e ${ENVIRONMENT}` + ); + process.exit(1); + } - return { - headers: { - "Set-Cookie": `ic_env=${encodeURIComponent( - `ic_root_key=${networkStatus.root_key}&PUBLIC_CANISTER_ID:backend=${canisterId}` - )}; SameSite=Lax;`, - }, - proxy: { - "/api": { target: networkStatus.api_url, changeOrigin: true }, - }, - }; + return { + headers: { + "Set-Cookie": `ic_env=${encodeURIComponent( + `ic_root_key=${networkStatus.root_key}&PUBLIC_CANISTER_ID:${CANISTER_NAME}=${canisterId}` + )}; SameSite=Lax;`, + }, + proxy: { + "/api": { target: networkStatus.api_url, changeOrigin: true }, + }, + }; } export default defineConfig(({ command }) => ({ diff --git a/motoko/who_am_i/src/frontend/vite.config.js b/motoko/who_am_i/src/frontend/vite.config.js index 7e3ea289d4..0e18d9ab02 100644 --- a/motoko/who_am_i/src/frontend/vite.config.js +++ b/motoko/who_am_i/src/frontend/vite.config.js @@ -3,18 +3,21 @@ import { execSync } from "child_process"; import react from "@vitejs/plugin-react"; import { icpBindgen } from "@icp-sdk/bindgen/plugins/vite"; +const CANISTER_NAME = "backend"; +const ENVIRONMENT = process.env.ICP_ENVIRONMENT || "local"; + function getDevServerConfig() { let networkStatus; try { networkStatus = JSON.parse( - execSync("icp network status -e local --json", { + execSync(`icp network status -e ${ENVIRONMENT} --json`, { encoding: "utf-8", stdio: "pipe", }) ); } catch { console.error( - "No local network running. Start it and deploy first:\n" + + `No network running for environment "${ENVIRONMENT}". Start it and deploy first:\n` + " icp network start -d && icp deploy" ); process.exit(1); @@ -22,14 +25,14 @@ function getDevServerConfig() { let canisterId; try { - canisterId = execSync("icp canister status backend -e local -i", { - encoding: "utf-8", - stdio: "pipe", - }).trim(); + canisterId = execSync( + `icp canister status ${CANISTER_NAME} -e ${ENVIRONMENT} -i`, + { encoding: "utf-8", stdio: "pipe" } + ).trim(); } catch { console.error( - "Canister 'backend' is not deployed on the local network. Deploy it first:\n" + - " icp deploy backend" + `Canister "${CANISTER_NAME}" is not deployed in environment "${ENVIRONMENT}". Deploy it first:\n` + + ` icp deploy ${CANISTER_NAME} -e ${ENVIRONMENT}` ); process.exit(1); } @@ -38,7 +41,7 @@ function getDevServerConfig() { replicaPort: new URL(networkStatus.api_url).port, headers: { "Set-Cookie": `ic_env=${encodeURIComponent( - `ic_root_key=${networkStatus.root_key}&PUBLIC_CANISTER_ID:backend=${canisterId}` + `ic_root_key=${networkStatus.root_key}&PUBLIC_CANISTER_ID:${CANISTER_NAME}=${canisterId}` )}; SameSite=Lax;`, }, proxy: { diff --git a/rust/daily_planner/frontend/vite.config.js b/rust/daily_planner/frontend/vite.config.js index 30cf450b32..3cabb9b717 100644 --- a/rust/daily_planner/frontend/vite.config.js +++ b/rust/daily_planner/frontend/vite.config.js @@ -3,18 +3,21 @@ import { execSync } from "child_process"; import react from "@vitejs/plugin-react"; import { icpBindgen } from "@icp-sdk/bindgen/plugins/vite"; +const CANISTER_NAME = "backend"; +const ENVIRONMENT = process.env.ICP_ENVIRONMENT || "local"; + function getDevServerConfig() { let networkStatus; try { networkStatus = JSON.parse( - execSync("icp network status -e local --json", { + execSync(`icp network status -e ${ENVIRONMENT} --json`, { encoding: "utf-8", stdio: "pipe", }) ); } catch { console.error( - "No local network running. Start it and deploy first:\n" + + `No network running for environment "${ENVIRONMENT}". Start it and deploy first:\n` + " icp network start -d && icp deploy" ); process.exit(1); @@ -22,14 +25,14 @@ function getDevServerConfig() { let canisterId; try { - canisterId = execSync("icp canister status backend -e local -i", { - encoding: "utf-8", - stdio: "pipe", - }).trim(); + canisterId = execSync( + `icp canister status ${CANISTER_NAME} -e ${ENVIRONMENT} -i`, + { encoding: "utf-8", stdio: "pipe" } + ).trim(); } catch { console.error( - "Canister 'backend' is not deployed on the local network. Deploy it first:\n" + - " icp deploy backend" + `Canister "${CANISTER_NAME}" is not deployed in environment "${ENVIRONMENT}". Deploy it first:\n` + + ` icp deploy ${CANISTER_NAME} -e ${ENVIRONMENT}` ); process.exit(1); } @@ -37,7 +40,7 @@ function getDevServerConfig() { return { headers: { "Set-Cookie": `ic_env=${encodeURIComponent( - `ic_root_key=${networkStatus.root_key}&PUBLIC_CANISTER_ID:backend=${canisterId}` + `ic_root_key=${networkStatus.root_key}&PUBLIC_CANISTER_ID:${CANISTER_NAME}=${canisterId}` )}; SameSite=Lax;`, }, proxy: { diff --git a/rust/evm_block_explorer/frontend/vite.config.js b/rust/evm_block_explorer/frontend/vite.config.js index acdade00c4..4e04e937b5 100644 --- a/rust/evm_block_explorer/frontend/vite.config.js +++ b/rust/evm_block_explorer/frontend/vite.config.js @@ -3,65 +3,67 @@ import { icpBindgen } from "@icp-sdk/bindgen/plugins/vite"; import react from "@vitejs/plugin-react"; import { execSync } from "child_process"; -export default defineConfig(({ command }) => { - const plugins = [ - react(), - icpBindgen({ - didFile: "../backend/backend.did", - outDir: "./src/bindings", - }), - ]; - - if (command !== "serve") { - return { plugins }; - } - - const environment = process.env.ICP_ENVIRONMENT || "local"; - const CANISTER_NAME = "backend"; +const CANISTER_NAME = "backend"; +const ENVIRONMENT = process.env.ICP_ENVIRONMENT || "local"; +function getDevServerConfig() { let networkStatus; try { networkStatus = JSON.parse( - execSync(`icp network status -e ${environment} --json`, { + execSync(`icp network status -e ${ENVIRONMENT} --json`, { encoding: "utf-8", stdio: "pipe", }) ); } catch { console.error( - `No local network running for environment "${environment}". Start it and deploy first:\n` + + `No network running for environment "${ENVIRONMENT}". Start it and deploy first:\n` + " icp network start -d && icp deploy" ); process.exit(1); } - const rootKey = networkStatus.root_key; - const proxyTarget = networkStatus.api_url; let canisterId; try { canisterId = execSync( - `icp canister status ${CANISTER_NAME} -e ${environment} -i`, + `icp canister status ${CANISTER_NAME} -e ${ENVIRONMENT} -i`, { encoding: "utf-8", stdio: "pipe" } ).trim(); } catch { console.error( - `Canister "${CANISTER_NAME}" is not deployed in environment "${environment}". Deploy it first:\n` + - ` icp deploy ${CANISTER_NAME} -e ${environment}` + `Canister "${CANISTER_NAME}" is not deployed in environment "${ENVIRONMENT}". Deploy it first:\n` + + ` icp deploy ${CANISTER_NAME} -e ${ENVIRONMENT}` ); process.exit(1); } return { - plugins, - server: { - headers: { - "Set-Cookie": `ic_env=${encodeURIComponent( - `PUBLIC_CANISTER_ID:${CANISTER_NAME}=${canisterId}&ic_root_key=${rootKey}` - )}; SameSite=Lax;`, - }, - proxy: { - "/api": { target: proxyTarget, changeOrigin: true }, - }, + headers: { + "Set-Cookie": `ic_env=${encodeURIComponent( + `ic_root_key=${networkStatus.root_key}&PUBLIC_CANISTER_ID:${CANISTER_NAME}=${canisterId}` + )}; SameSite=Lax;`, }, + proxy: { + "/api": { target: networkStatus.api_url, changeOrigin: true }, + }, + }; +} + +export default defineConfig(({ command }) => { + const plugins = [ + react(), + icpBindgen({ + didFile: "../backend/backend.did", + outDir: "./src/bindings", + }), + ]; + + if (command !== "serve") { + return { plugins }; + } + + return { + plugins, + server: getDevServerConfig(), }; }); diff --git a/rust/face-recognition/frontend/vite.config.js b/rust/face-recognition/frontend/vite.config.js index 82270e59da..b85659cc7f 100644 --- a/rust/face-recognition/frontend/vite.config.js +++ b/rust/face-recognition/frontend/vite.config.js @@ -2,73 +2,67 @@ import { defineConfig } from "vite"; import { icpBindgen } from "@icp-sdk/bindgen/plugins/vite"; import { execSync } from "child_process"; -export default defineConfig(({ command }) => { - const plugins = [ - icpBindgen({ - didFile: "../backend/backend.did", - outDir: "./src/bindings", - }), - ]; - - // If we're only building this is enough - if (command !== "serve") { - return { plugins }; - } - - // If we're running the local npm dev server, we're going to look up the - // local network's root key and the relevant canister ids. - const environment = process.env.ICP_ENVIRONMENT || "local"; - const CANISTER_NAME = "backend"; +const CANISTER_NAME = "backend"; +const ENVIRONMENT = process.env.ICP_ENVIRONMENT || "local"; +function getDevServerConfig() { let networkStatus; try { networkStatus = JSON.parse( - execSync(`icp network status -e ${environment} --json`, { + execSync(`icp network status -e ${ENVIRONMENT} --json`, { encoding: "utf-8", stdio: "pipe", }) ); } catch { console.error( - `No local network running for environment "${environment}". Start it and deploy first:\n` + + `No network running for environment "${ENVIRONMENT}". Start it and deploy first:\n` + " icp network start -d && icp deploy" ); process.exit(1); } - const rootKey = networkStatus.root_key; - const proxyTarget = networkStatus.api_url; - // Backend must be deployed before starting dev server let canisterId; try { canisterId = execSync( - `icp canister status ${CANISTER_NAME} -e ${environment} -i`, + `icp canister status ${CANISTER_NAME} -e ${ENVIRONMENT} -i`, { encoding: "utf-8", stdio: "pipe" } ).trim(); } catch { console.error( - `Canister "${CANISTER_NAME}" is not deployed in environment "${environment}". Deploy it first:\n` + - ` icp deploy ${CANISTER_NAME} -e ${environment}` + `Canister "${CANISTER_NAME}" is not deployed in environment "${ENVIRONMENT}". Deploy it first:\n` + + ` icp deploy ${CANISTER_NAME} -e ${ENVIRONMENT}` ); process.exit(1); } - const server = { + return { headers: { "Set-Cookie": `ic_env=${encodeURIComponent( - `PUBLIC_CANISTER_ID:${CANISTER_NAME}=${canisterId}&ic_root_key=${rootKey}` + `ic_root_key=${networkStatus.root_key}&PUBLIC_CANISTER_ID:${CANISTER_NAME}=${canisterId}` )}; SameSite=Lax;`, }, proxy: { - "/api": { - target: proxyTarget, - changeOrigin: true, - }, + "/api": { target: networkStatus.api_url, changeOrigin: true }, }, }; +} + +export default defineConfig(({ command }) => { + const plugins = [ + icpBindgen({ + didFile: "../backend/backend.did", + outDir: "./src/bindings", + }), + ]; + + // If we're only building this is enough + if (command !== "serve") { + return { plugins }; + } return { plugins, - server, + server: getDevServerConfig(), }; }); diff --git a/rust/flying_ninja/frontend/vite.config.js b/rust/flying_ninja/frontend/vite.config.js index 1452722fab..8cc5533817 100644 --- a/rust/flying_ninja/frontend/vite.config.js +++ b/rust/flying_ninja/frontend/vite.config.js @@ -3,18 +3,21 @@ import react from "@vitejs/plugin-react"; import { execSync } from "child_process"; import { icpBindgen } from "@icp-sdk/bindgen/plugins/vite"; +const CANISTER_NAME = "backend"; +const ENVIRONMENT = process.env.ICP_ENVIRONMENT || "local"; + function getDevServerConfig() { let networkStatus; try { networkStatus = JSON.parse( - execSync("icp network status -e local --json", { + execSync(`icp network status -e ${ENVIRONMENT} --json`, { encoding: "utf-8", stdio: "pipe", }) ); } catch { console.error( - "No local network running. Start it and deploy first:\n" + + `No network running for environment "${ENVIRONMENT}". Start it and deploy first:\n` + " icp network start -d && icp deploy" ); process.exit(1); @@ -22,14 +25,14 @@ function getDevServerConfig() { let canisterId; try { - canisterId = execSync("icp canister status backend -e local -i", { - encoding: "utf-8", - stdio: "pipe", - }).trim(); + canisterId = execSync( + `icp canister status ${CANISTER_NAME} -e ${ENVIRONMENT} -i`, + { encoding: "utf-8", stdio: "pipe" } + ).trim(); } catch { console.error( - "Canister 'backend' is not deployed on the local network. Deploy it first:\n" + - " icp deploy backend" + `Canister "${CANISTER_NAME}" is not deployed in environment "${ENVIRONMENT}". Deploy it first:\n` + + ` icp deploy ${CANISTER_NAME} -e ${ENVIRONMENT}` ); process.exit(1); } @@ -37,7 +40,7 @@ function getDevServerConfig() { return { headers: { "Set-Cookie": `ic_env=${encodeURIComponent( - `ic_root_key=${networkStatus.root_key}&PUBLIC_CANISTER_ID:backend=${canisterId}` + `ic_root_key=${networkStatus.root_key}&PUBLIC_CANISTER_ID:${CANISTER_NAME}=${canisterId}` )}; SameSite=Lax;`, }, proxy: { diff --git a/rust/hello_world/frontend/vite.config.js b/rust/hello_world/frontend/vite.config.js index 82270e59da..b85659cc7f 100644 --- a/rust/hello_world/frontend/vite.config.js +++ b/rust/hello_world/frontend/vite.config.js @@ -2,73 +2,67 @@ import { defineConfig } from "vite"; import { icpBindgen } from "@icp-sdk/bindgen/plugins/vite"; import { execSync } from "child_process"; -export default defineConfig(({ command }) => { - const plugins = [ - icpBindgen({ - didFile: "../backend/backend.did", - outDir: "./src/bindings", - }), - ]; - - // If we're only building this is enough - if (command !== "serve") { - return { plugins }; - } - - // If we're running the local npm dev server, we're going to look up the - // local network's root key and the relevant canister ids. - const environment = process.env.ICP_ENVIRONMENT || "local"; - const CANISTER_NAME = "backend"; +const CANISTER_NAME = "backend"; +const ENVIRONMENT = process.env.ICP_ENVIRONMENT || "local"; +function getDevServerConfig() { let networkStatus; try { networkStatus = JSON.parse( - execSync(`icp network status -e ${environment} --json`, { + execSync(`icp network status -e ${ENVIRONMENT} --json`, { encoding: "utf-8", stdio: "pipe", }) ); } catch { console.error( - `No local network running for environment "${environment}". Start it and deploy first:\n` + + `No network running for environment "${ENVIRONMENT}". Start it and deploy first:\n` + " icp network start -d && icp deploy" ); process.exit(1); } - const rootKey = networkStatus.root_key; - const proxyTarget = networkStatus.api_url; - // Backend must be deployed before starting dev server let canisterId; try { canisterId = execSync( - `icp canister status ${CANISTER_NAME} -e ${environment} -i`, + `icp canister status ${CANISTER_NAME} -e ${ENVIRONMENT} -i`, { encoding: "utf-8", stdio: "pipe" } ).trim(); } catch { console.error( - `Canister "${CANISTER_NAME}" is not deployed in environment "${environment}". Deploy it first:\n` + - ` icp deploy ${CANISTER_NAME} -e ${environment}` + `Canister "${CANISTER_NAME}" is not deployed in environment "${ENVIRONMENT}". Deploy it first:\n` + + ` icp deploy ${CANISTER_NAME} -e ${ENVIRONMENT}` ); process.exit(1); } - const server = { + return { headers: { "Set-Cookie": `ic_env=${encodeURIComponent( - `PUBLIC_CANISTER_ID:${CANISTER_NAME}=${canisterId}&ic_root_key=${rootKey}` + `ic_root_key=${networkStatus.root_key}&PUBLIC_CANISTER_ID:${CANISTER_NAME}=${canisterId}` )}; SameSite=Lax;`, }, proxy: { - "/api": { - target: proxyTarget, - changeOrigin: true, - }, + "/api": { target: networkStatus.api_url, changeOrigin: true }, }, }; +} + +export default defineConfig(({ command }) => { + const plugins = [ + icpBindgen({ + didFile: "../backend/backend.did", + outDir: "./src/bindings", + }), + ]; + + // If we're only building this is enough + if (command !== "serve") { + return { plugins }; + } return { plugins, - server, + server: getDevServerConfig(), }; }); diff --git a/rust/image-classification/frontend/vite.config.js b/rust/image-classification/frontend/vite.config.js index 82270e59da..b85659cc7f 100644 --- a/rust/image-classification/frontend/vite.config.js +++ b/rust/image-classification/frontend/vite.config.js @@ -2,73 +2,67 @@ import { defineConfig } from "vite"; import { icpBindgen } from "@icp-sdk/bindgen/plugins/vite"; import { execSync } from "child_process"; -export default defineConfig(({ command }) => { - const plugins = [ - icpBindgen({ - didFile: "../backend/backend.did", - outDir: "./src/bindings", - }), - ]; - - // If we're only building this is enough - if (command !== "serve") { - return { plugins }; - } - - // If we're running the local npm dev server, we're going to look up the - // local network's root key and the relevant canister ids. - const environment = process.env.ICP_ENVIRONMENT || "local"; - const CANISTER_NAME = "backend"; +const CANISTER_NAME = "backend"; +const ENVIRONMENT = process.env.ICP_ENVIRONMENT || "local"; +function getDevServerConfig() { let networkStatus; try { networkStatus = JSON.parse( - execSync(`icp network status -e ${environment} --json`, { + execSync(`icp network status -e ${ENVIRONMENT} --json`, { encoding: "utf-8", stdio: "pipe", }) ); } catch { console.error( - `No local network running for environment "${environment}". Start it and deploy first:\n` + + `No network running for environment "${ENVIRONMENT}". Start it and deploy first:\n` + " icp network start -d && icp deploy" ); process.exit(1); } - const rootKey = networkStatus.root_key; - const proxyTarget = networkStatus.api_url; - // Backend must be deployed before starting dev server let canisterId; try { canisterId = execSync( - `icp canister status ${CANISTER_NAME} -e ${environment} -i`, + `icp canister status ${CANISTER_NAME} -e ${ENVIRONMENT} -i`, { encoding: "utf-8", stdio: "pipe" } ).trim(); } catch { console.error( - `Canister "${CANISTER_NAME}" is not deployed in environment "${environment}". Deploy it first:\n` + - ` icp deploy ${CANISTER_NAME} -e ${environment}` + `Canister "${CANISTER_NAME}" is not deployed in environment "${ENVIRONMENT}". Deploy it first:\n` + + ` icp deploy ${CANISTER_NAME} -e ${ENVIRONMENT}` ); process.exit(1); } - const server = { + return { headers: { "Set-Cookie": `ic_env=${encodeURIComponent( - `PUBLIC_CANISTER_ID:${CANISTER_NAME}=${canisterId}&ic_root_key=${rootKey}` + `ic_root_key=${networkStatus.root_key}&PUBLIC_CANISTER_ID:${CANISTER_NAME}=${canisterId}` )}; SameSite=Lax;`, }, proxy: { - "/api": { - target: proxyTarget, - changeOrigin: true, - }, + "/api": { target: networkStatus.api_url, changeOrigin: true }, }, }; +} + +export default defineConfig(({ command }) => { + const plugins = [ + icpBindgen({ + didFile: "../backend/backend.did", + outDir: "./src/bindings", + }), + ]; + + // If we're only building this is enough + if (command !== "serve") { + return { plugins }; + } return { plugins, - server, + server: getDevServerConfig(), }; }); diff --git a/rust/llm_chatbot/frontend/vite.config.js b/rust/llm_chatbot/frontend/vite.config.js index 96eb839a8b..468af6aaaa 100644 --- a/rust/llm_chatbot/frontend/vite.config.js +++ b/rust/llm_chatbot/frontend/vite.config.js @@ -3,72 +3,69 @@ import react from "@vitejs/plugin-react"; import { icpBindgen } from "@icp-sdk/bindgen/plugins/vite"; import { execSync } from "child_process"; -export default defineConfig(({ command }) => { - const plugins = [ - react(), - icpBindgen({ - didFile: "../backend/backend.did", - outDir: "./src/bindings", - }), - ]; - - // Build only — no dev-server setup needed - if (command !== "serve") { - return { plugins }; - } - - // Dev server: look up the local network root key and backend canister ID - const environment = process.env.ICP_ENVIRONMENT || "local"; - const CANISTER_NAME = "backend"; +const CANISTER_NAME = "backend"; +const ENVIRONMENT = process.env.ICP_ENVIRONMENT || "local"; +function getDevServerConfig() { let networkStatus; try { networkStatus = JSON.parse( - execSync(`icp network status -e ${environment} --json`, { + execSync(`icp network status -e ${ENVIRONMENT} --json`, { encoding: "utf-8", stdio: "pipe", }) ); } catch { console.error( - `No local network running for environment "${environment}". Start it and deploy first:\n` + + `No network running for environment "${ENVIRONMENT}". Start it and deploy first:\n` + " icp network start -d && icp deploy" ); process.exit(1); } - const rootKey = networkStatus.root_key; - const proxyTarget = networkStatus.api_url; let canisterId; try { canisterId = execSync( - `icp canister status ${CANISTER_NAME} -e ${environment} -i`, + `icp canister status ${CANISTER_NAME} -e ${ENVIRONMENT} -i`, { encoding: "utf-8", stdio: "pipe" } ).trim(); } catch { console.error( - `Canister "${CANISTER_NAME}" is not deployed in environment "${environment}". Deploy it first:\n` + - ` icp deploy ${CANISTER_NAME} -e ${environment}` + `Canister "${CANISTER_NAME}" is not deployed in environment "${ENVIRONMENT}". Deploy it first:\n` + + ` icp deploy ${CANISTER_NAME} -e ${ENVIRONMENT}` ); process.exit(1); } - const server = { + return { headers: { "Set-Cookie": `ic_env=${encodeURIComponent( - `PUBLIC_CANISTER_ID:${CANISTER_NAME}=${canisterId}&ic_root_key=${rootKey}` + `ic_root_key=${networkStatus.root_key}&PUBLIC_CANISTER_ID:${CANISTER_NAME}=${canisterId}` )}; SameSite=Lax;`, }, proxy: { - "/api": { - target: proxyTarget, - changeOrigin: true, - }, + "/api": { target: networkStatus.api_url, changeOrigin: true }, }, }; +} +export default defineConfig(({ command }) => { + const plugins = [ + react(), + icpBindgen({ + didFile: "../backend/backend.did", + outDir: "./src/bindings", + }), + ]; + + // Build only — no dev-server setup needed + if (command !== "serve") { + return { plugins }; + } + + // Dev server: look up the local network root key and backend canister ID return { plugins, - server, + server: getDevServerConfig(), }; }); diff --git a/rust/qrcode/frontend/vite.config.js b/rust/qrcode/frontend/vite.config.js index 6c94031262..26a82aaec9 100644 --- a/rust/qrcode/frontend/vite.config.js +++ b/rust/qrcode/frontend/vite.config.js @@ -2,18 +2,21 @@ import { defineConfig } from "vite"; import { execSync } from "child_process"; import { icpBindgen } from "@icp-sdk/bindgen/plugins/vite"; +const CANISTER_NAME = "backend"; +const ENVIRONMENT = process.env.ICP_ENVIRONMENT || "local"; + function getDevServerConfig() { let networkStatus; try { networkStatus = JSON.parse( - execSync("icp network status -e local --json", { + execSync(`icp network status -e ${ENVIRONMENT} --json`, { encoding: "utf-8", stdio: "pipe", }) ); } catch { console.error( - "No local network running. Start it and deploy first:\n" + + `No network running for environment "${ENVIRONMENT}". Start it and deploy first:\n` + " icp network start -d && icp deploy" ); process.exit(1); @@ -21,14 +24,14 @@ function getDevServerConfig() { let canisterId; try { - canisterId = execSync("icp canister status backend -e local -i", { - encoding: "utf-8", - stdio: "pipe", - }).trim(); + canisterId = execSync( + `icp canister status ${CANISTER_NAME} -e ${ENVIRONMENT} -i`, + { encoding: "utf-8", stdio: "pipe" } + ).trim(); } catch { console.error( - "Canister 'backend' is not deployed on the local network. Deploy it first:\n" + - " icp deploy backend" + `Canister "${CANISTER_NAME}" is not deployed in environment "${ENVIRONMENT}". Deploy it first:\n` + + ` icp deploy ${CANISTER_NAME} -e ${ENVIRONMENT}` ); process.exit(1); } @@ -36,7 +39,7 @@ function getDevServerConfig() { return { headers: { "Set-Cookie": `ic_env=${encodeURIComponent( - `ic_root_key=${networkStatus.root_key}&PUBLIC_CANISTER_ID:backend=${canisterId}` + `ic_root_key=${networkStatus.root_key}&PUBLIC_CANISTER_ID:${CANISTER_NAME}=${canisterId}` )}; SameSite=Lax;`, }, proxy: { diff --git a/rust/vetkeys/basic_vetkd/frontend/vite.config.js b/rust/vetkeys/basic_vetkd/frontend/vite.config.js index 07fd35b1f4..6fc36eee1b 100644 --- a/rust/vetkeys/basic_vetkd/frontend/vite.config.js +++ b/rust/vetkeys/basic_vetkd/frontend/vite.config.js @@ -2,18 +2,21 @@ import { defineConfig } from "vite"; import { execSync } from "child_process"; import { icpBindgen } from "@icp-sdk/bindgen/plugins/vite"; +const CANISTER_NAME = "backend"; +const ENVIRONMENT = process.env.ICP_ENVIRONMENT || "local"; + function getDevServerConfig() { let networkStatus; try { networkStatus = JSON.parse( - execSync("icp network status -e local --json", { + execSync(`icp network status -e ${ENVIRONMENT} --json`, { encoding: "utf-8", stdio: "pipe", }) ); } catch { console.error( - "No local network running. Start it and deploy first:\n" + + `No network running for environment "${ENVIRONMENT}". Start it and deploy first:\n` + " icp network start -d && icp deploy" ); process.exit(1); @@ -21,14 +24,14 @@ function getDevServerConfig() { let canisterId; try { - canisterId = execSync("icp canister status backend -e local -i", { - encoding: "utf-8", - stdio: "pipe", - }).trim(); + canisterId = execSync( + `icp canister status ${CANISTER_NAME} -e ${ENVIRONMENT} -i`, + { encoding: "utf-8", stdio: "pipe" } + ).trim(); } catch { console.error( - "Canister 'backend' is not deployed on the local network. Deploy it first:\n" + - " icp deploy backend" + `Canister "${CANISTER_NAME}" is not deployed in environment "${ENVIRONMENT}". Deploy it first:\n` + + ` icp deploy ${CANISTER_NAME} -e ${ENVIRONMENT}` ); process.exit(1); } @@ -36,7 +39,7 @@ function getDevServerConfig() { return { headers: { "Set-Cookie": `ic_env=${encodeURIComponent( - `ic_root_key=${networkStatus.root_key}&PUBLIC_CANISTER_ID:backend=${canisterId}` + `ic_root_key=${networkStatus.root_key}&PUBLIC_CANISTER_ID:${CANISTER_NAME}=${canisterId}` )}; SameSite=Lax;`, }, proxy: { diff --git a/rust/vetkeys/password_manager_with_metadata/frontend/vite.config.js b/rust/vetkeys/password_manager_with_metadata/frontend/vite.config.js index 25eb541f58..a0f092a005 100644 --- a/rust/vetkeys/password_manager_with_metadata/frontend/vite.config.js +++ b/rust/vetkeys/password_manager_with_metadata/frontend/vite.config.js @@ -6,47 +6,50 @@ import css from "rollup-plugin-css-only"; import { icpBindgen } from "@icp-sdk/bindgen/plugins/vite"; import { execSync } from "child_process"; +const CANISTER_NAME = "backend"; +const ENVIRONMENT = process.env.ICP_ENVIRONMENT || "local"; + function getDevServerConfig() { - let networkStatus; - try { - networkStatus = JSON.parse( - execSync("icp network status -e local --json", { - encoding: "utf-8", - stdio: "pipe", - }) - ); - } catch { - console.error( - "No local network running. Start it and deploy first:\n" + - " icp network start -d && icp deploy" - ); - process.exit(1); - } + let networkStatus; + try { + networkStatus = JSON.parse( + execSync(`icp network status -e ${ENVIRONMENT} --json`, { + encoding: "utf-8", + stdio: "pipe", + }) + ); + } catch { + console.error( + `No network running for environment "${ENVIRONMENT}". Start it and deploy first:\n` + + " icp network start -d && icp deploy" + ); + process.exit(1); + } - let canisterId; - try { - canisterId = execSync("icp canister status backend -e local -i", { - encoding: "utf-8", - stdio: "pipe", - }).trim(); - } catch { - console.error( - "Canister 'backend' is not deployed on the local network. Deploy it first:\n" + - " icp deploy backend" - ); - process.exit(1); - } + let canisterId; + try { + canisterId = execSync( + `icp canister status ${CANISTER_NAME} -e ${ENVIRONMENT} -i`, + { encoding: "utf-8", stdio: "pipe" } + ).trim(); + } catch { + console.error( + `Canister "${CANISTER_NAME}" is not deployed in environment "${ENVIRONMENT}". Deploy it first:\n` + + ` icp deploy ${CANISTER_NAME} -e ${ENVIRONMENT}` + ); + process.exit(1); + } - return { - headers: { - "Set-Cookie": `ic_env=${encodeURIComponent( - `ic_root_key=${networkStatus.root_key}&PUBLIC_CANISTER_ID:backend=${canisterId}` - )}; SameSite=Lax;`, - }, - proxy: { - "/api": { target: networkStatus.api_url, changeOrigin: true }, - }, - }; + return { + headers: { + "Set-Cookie": `ic_env=${encodeURIComponent( + `ic_root_key=${networkStatus.root_key}&PUBLIC_CANISTER_ID:${CANISTER_NAME}=${canisterId}` + )}; SameSite=Lax;`, + }, + proxy: { + "/api": { target: networkStatus.api_url, changeOrigin: true }, + }, + }; } export default defineConfig(({ command }) => ({ diff --git a/rust/who_am_i/src/frontend/vite.config.js b/rust/who_am_i/src/frontend/vite.config.js index 7e3ea289d4..0e18d9ab02 100644 --- a/rust/who_am_i/src/frontend/vite.config.js +++ b/rust/who_am_i/src/frontend/vite.config.js @@ -3,18 +3,21 @@ import { execSync } from "child_process"; import react from "@vitejs/plugin-react"; import { icpBindgen } from "@icp-sdk/bindgen/plugins/vite"; +const CANISTER_NAME = "backend"; +const ENVIRONMENT = process.env.ICP_ENVIRONMENT || "local"; + function getDevServerConfig() { let networkStatus; try { networkStatus = JSON.parse( - execSync("icp network status -e local --json", { + execSync(`icp network status -e ${ENVIRONMENT} --json`, { encoding: "utf-8", stdio: "pipe", }) ); } catch { console.error( - "No local network running. Start it and deploy first:\n" + + `No network running for environment "${ENVIRONMENT}". Start it and deploy first:\n` + " icp network start -d && icp deploy" ); process.exit(1); @@ -22,14 +25,14 @@ function getDevServerConfig() { let canisterId; try { - canisterId = execSync("icp canister status backend -e local -i", { - encoding: "utf-8", - stdio: "pipe", - }).trim(); + canisterId = execSync( + `icp canister status ${CANISTER_NAME} -e ${ENVIRONMENT} -i`, + { encoding: "utf-8", stdio: "pipe" } + ).trim(); } catch { console.error( - "Canister 'backend' is not deployed on the local network. Deploy it first:\n" + - " icp deploy backend" + `Canister "${CANISTER_NAME}" is not deployed in environment "${ENVIRONMENT}". Deploy it first:\n` + + ` icp deploy ${CANISTER_NAME} -e ${ENVIRONMENT}` ); process.exit(1); } @@ -38,7 +41,7 @@ function getDevServerConfig() { replicaPort: new URL(networkStatus.api_url).port, headers: { "Set-Cookie": `ic_env=${encodeURIComponent( - `ic_root_key=${networkStatus.root_key}&PUBLIC_CANISTER_ID:backend=${canisterId}` + `ic_root_key=${networkStatus.root_key}&PUBLIC_CANISTER_ID:${CANISTER_NAME}=${canisterId}` )}; SameSite=Lax;`, }, proxy: { From ef57425a653c1b980848bd16e8223bebb78d4d3d Mon Sep 17 00:00:00 2001 From: Marco Walz Date: Thu, 27 Aug 2026 13:48:13 +0200 Subject: [PATCH 6/6] fix: make the no-network remedy honour ENVIRONMENT, and name a bad one MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Copilot spotted that the network guard's suggested command dropped the environment while the canister guard's kept it, so with ICP_ENVIRONMENT set the printed remedy pointed at the default environment rather than the one the dev server had just failed to reach. It was the only remaining place: across all 23 configs only four icp commands are emitted, and the other three (`network status`, `canister status`, `deploy `) already carried `-e ${ENVIRONMENT}`. icp network start -d -e ${ENVIRONMENT} && icp deploy -e ${ENVIRONMENT} Checking that also turned up a second case worth separating. `icp network status -e ` fails for two different reasons, and treating both as "network not running" is only right for one of them: $ icp network status -e nope --json Error: project does not contain an environment named 'nope' A typo'd or undefined ICP_ENVIRONMENT was reported as a stopped network, with a remedy that could not work — `icp network start -e nope` fails the same way. The guard now branches on that stderr and says so instead: Unknown environment "nope". Check ICP_ENVIRONMENT against the environments in icp.yaml. For a genuinely non-local environment the assumption holds and needs no special case: `icp network status -e ic --json` succeeds without any `environments:` block, returning the mainnet api_url, so the guard passes and the dev server proxies to mainnet. Helper remains byte-identical across all 23 (one md5). Verified on rust/qrcode against a network on port 8127: no network, unknown environment, network-up-not-deployed, and the deployed happy path with a byte-identical proxied /api/v2/status. Co-Authored-By: Claude Opus 5 (1M context) --- motoko/cert-var/frontend/vite.config.js | 16 +++++++++++----- motoko/daily_planner/frontend/vite.config.js | 16 +++++++++++----- .../evm_block_explorer/frontend/vite.config.js | 16 +++++++++++----- motoko/filevault/frontend/vite.config.js | 16 +++++++++++----- motoko/flying_ninja/frontend/vite.config.js | 16 +++++++++++----- motoko/hello_world/frontend/vite.config.js | 16 +++++++++++----- motoko/llm_chatbot/frontend/vite.config.js | 16 +++++++++++----- motoko/random_maze/frontend/vite.config.js | 16 +++++++++++----- motoko/superheroes/frontend/vite.config.js | 16 +++++++++++----- .../vetkeys/basic_vetkd/frontend/vite.config.js | 16 +++++++++++----- .../frontend/vite.config.js | 16 +++++++++++----- motoko/who_am_i/src/frontend/vite.config.js | 16 +++++++++++----- rust/daily_planner/frontend/vite.config.js | 16 +++++++++++----- rust/evm_block_explorer/frontend/vite.config.js | 16 +++++++++++----- rust/face-recognition/frontend/vite.config.js | 16 +++++++++++----- rust/flying_ninja/frontend/vite.config.js | 16 +++++++++++----- rust/hello_world/frontend/vite.config.js | 16 +++++++++++----- .../image-classification/frontend/vite.config.js | 16 +++++++++++----- rust/llm_chatbot/frontend/vite.config.js | 16 +++++++++++----- rust/qrcode/frontend/vite.config.js | 16 +++++++++++----- rust/vetkeys/basic_vetkd/frontend/vite.config.js | 16 +++++++++++----- .../frontend/vite.config.js | 16 +++++++++++----- rust/who_am_i/src/frontend/vite.config.js | 16 +++++++++++----- 23 files changed, 253 insertions(+), 115 deletions(-) diff --git a/motoko/cert-var/frontend/vite.config.js b/motoko/cert-var/frontend/vite.config.js index 26a82aaec9..c2d473eec3 100644 --- a/motoko/cert-var/frontend/vite.config.js +++ b/motoko/cert-var/frontend/vite.config.js @@ -14,11 +14,17 @@ function getDevServerConfig() { stdio: "pipe", }) ); - } catch { - console.error( - `No network running for environment "${ENVIRONMENT}". Start it and deploy first:\n` + - " icp network start -d && icp deploy" - ); + } catch (error) { + if (String(error.stderr).includes("does not contain an environment named")) { + console.error( + `Unknown environment "${ENVIRONMENT}". Check ICP_ENVIRONMENT against the environments in icp.yaml.` + ); + } else { + console.error( + `No network running for environment "${ENVIRONMENT}". Start it and deploy first:\n` + + ` icp network start -d -e ${ENVIRONMENT} && icp deploy -e ${ENVIRONMENT}` + ); + } process.exit(1); } diff --git a/motoko/daily_planner/frontend/vite.config.js b/motoko/daily_planner/frontend/vite.config.js index 3cabb9b717..e62b05d93d 100644 --- a/motoko/daily_planner/frontend/vite.config.js +++ b/motoko/daily_planner/frontend/vite.config.js @@ -15,11 +15,17 @@ function getDevServerConfig() { stdio: "pipe", }) ); - } catch { - console.error( - `No network running for environment "${ENVIRONMENT}". Start it and deploy first:\n` + - " icp network start -d && icp deploy" - ); + } catch (error) { + if (String(error.stderr).includes("does not contain an environment named")) { + console.error( + `Unknown environment "${ENVIRONMENT}". Check ICP_ENVIRONMENT against the environments in icp.yaml.` + ); + } else { + console.error( + `No network running for environment "${ENVIRONMENT}". Start it and deploy first:\n` + + ` icp network start -d -e ${ENVIRONMENT} && icp deploy -e ${ENVIRONMENT}` + ); + } process.exit(1); } diff --git a/motoko/evm_block_explorer/frontend/vite.config.js b/motoko/evm_block_explorer/frontend/vite.config.js index 4e04e937b5..75825dac6d 100644 --- a/motoko/evm_block_explorer/frontend/vite.config.js +++ b/motoko/evm_block_explorer/frontend/vite.config.js @@ -15,11 +15,17 @@ function getDevServerConfig() { stdio: "pipe", }) ); - } catch { - console.error( - `No network running for environment "${ENVIRONMENT}". Start it and deploy first:\n` + - " icp network start -d && icp deploy" - ); + } catch (error) { + if (String(error.stderr).includes("does not contain an environment named")) { + console.error( + `Unknown environment "${ENVIRONMENT}". Check ICP_ENVIRONMENT against the environments in icp.yaml.` + ); + } else { + console.error( + `No network running for environment "${ENVIRONMENT}". Start it and deploy first:\n` + + ` icp network start -d -e ${ENVIRONMENT} && icp deploy -e ${ENVIRONMENT}` + ); + } process.exit(1); } diff --git a/motoko/filevault/frontend/vite.config.js b/motoko/filevault/frontend/vite.config.js index 0e18d9ab02..46d000e42b 100644 --- a/motoko/filevault/frontend/vite.config.js +++ b/motoko/filevault/frontend/vite.config.js @@ -15,11 +15,17 @@ function getDevServerConfig() { stdio: "pipe", }) ); - } catch { - console.error( - `No network running for environment "${ENVIRONMENT}". Start it and deploy first:\n` + - " icp network start -d && icp deploy" - ); + } catch (error) { + if (String(error.stderr).includes("does not contain an environment named")) { + console.error( + `Unknown environment "${ENVIRONMENT}". Check ICP_ENVIRONMENT against the environments in icp.yaml.` + ); + } else { + console.error( + `No network running for environment "${ENVIRONMENT}". Start it and deploy first:\n` + + ` icp network start -d -e ${ENVIRONMENT} && icp deploy -e ${ENVIRONMENT}` + ); + } process.exit(1); } diff --git a/motoko/flying_ninja/frontend/vite.config.js b/motoko/flying_ninja/frontend/vite.config.js index 8cc5533817..a9edbaa764 100644 --- a/motoko/flying_ninja/frontend/vite.config.js +++ b/motoko/flying_ninja/frontend/vite.config.js @@ -15,11 +15,17 @@ function getDevServerConfig() { stdio: "pipe", }) ); - } catch { - console.error( - `No network running for environment "${ENVIRONMENT}". Start it and deploy first:\n` + - " icp network start -d && icp deploy" - ); + } catch (error) { + if (String(error.stderr).includes("does not contain an environment named")) { + console.error( + `Unknown environment "${ENVIRONMENT}". Check ICP_ENVIRONMENT against the environments in icp.yaml.` + ); + } else { + console.error( + `No network running for environment "${ENVIRONMENT}". Start it and deploy first:\n` + + ` icp network start -d -e ${ENVIRONMENT} && icp deploy -e ${ENVIRONMENT}` + ); + } process.exit(1); } diff --git a/motoko/hello_world/frontend/vite.config.js b/motoko/hello_world/frontend/vite.config.js index b85659cc7f..c0f5f4f211 100644 --- a/motoko/hello_world/frontend/vite.config.js +++ b/motoko/hello_world/frontend/vite.config.js @@ -14,11 +14,17 @@ function getDevServerConfig() { stdio: "pipe", }) ); - } catch { - console.error( - `No network running for environment "${ENVIRONMENT}". Start it and deploy first:\n` + - " icp network start -d && icp deploy" - ); + } catch (error) { + if (String(error.stderr).includes("does not contain an environment named")) { + console.error( + `Unknown environment "${ENVIRONMENT}". Check ICP_ENVIRONMENT against the environments in icp.yaml.` + ); + } else { + console.error( + `No network running for environment "${ENVIRONMENT}". Start it and deploy first:\n` + + ` icp network start -d -e ${ENVIRONMENT} && icp deploy -e ${ENVIRONMENT}` + ); + } process.exit(1); } diff --git a/motoko/llm_chatbot/frontend/vite.config.js b/motoko/llm_chatbot/frontend/vite.config.js index 468af6aaaa..da95039aa5 100644 --- a/motoko/llm_chatbot/frontend/vite.config.js +++ b/motoko/llm_chatbot/frontend/vite.config.js @@ -15,11 +15,17 @@ function getDevServerConfig() { stdio: "pipe", }) ); - } catch { - console.error( - `No network running for environment "${ENVIRONMENT}". Start it and deploy first:\n` + - " icp network start -d && icp deploy" - ); + } catch (error) { + if (String(error.stderr).includes("does not contain an environment named")) { + console.error( + `Unknown environment "${ENVIRONMENT}". Check ICP_ENVIRONMENT against the environments in icp.yaml.` + ); + } else { + console.error( + `No network running for environment "${ENVIRONMENT}". Start it and deploy first:\n` + + ` icp network start -d -e ${ENVIRONMENT} && icp deploy -e ${ENVIRONMENT}` + ); + } process.exit(1); } diff --git a/motoko/random_maze/frontend/vite.config.js b/motoko/random_maze/frontend/vite.config.js index 3cabb9b717..e62b05d93d 100644 --- a/motoko/random_maze/frontend/vite.config.js +++ b/motoko/random_maze/frontend/vite.config.js @@ -15,11 +15,17 @@ function getDevServerConfig() { stdio: "pipe", }) ); - } catch { - console.error( - `No network running for environment "${ENVIRONMENT}". Start it and deploy first:\n` + - " icp network start -d && icp deploy" - ); + } catch (error) { + if (String(error.stderr).includes("does not contain an environment named")) { + console.error( + `Unknown environment "${ENVIRONMENT}". Check ICP_ENVIRONMENT against the environments in icp.yaml.` + ); + } else { + console.error( + `No network running for environment "${ENVIRONMENT}". Start it and deploy first:\n` + + ` icp network start -d -e ${ENVIRONMENT} && icp deploy -e ${ENVIRONMENT}` + ); + } process.exit(1); } diff --git a/motoko/superheroes/frontend/vite.config.js b/motoko/superheroes/frontend/vite.config.js index 571d590c1a..f982dfd3fd 100644 --- a/motoko/superheroes/frontend/vite.config.js +++ b/motoko/superheroes/frontend/vite.config.js @@ -15,11 +15,17 @@ function getDevServerConfig() { stdio: "pipe", }) ); - } catch { - console.error( - `No network running for environment "${ENVIRONMENT}". Start it and deploy first:\n` + - " icp network start -d && icp deploy" - ); + } catch (error) { + if (String(error.stderr).includes("does not contain an environment named")) { + console.error( + `Unknown environment "${ENVIRONMENT}". Check ICP_ENVIRONMENT against the environments in icp.yaml.` + ); + } else { + console.error( + `No network running for environment "${ENVIRONMENT}". Start it and deploy first:\n` + + ` icp network start -d -e ${ENVIRONMENT} && icp deploy -e ${ENVIRONMENT}` + ); + } process.exit(1); } diff --git a/motoko/vetkeys/basic_vetkd/frontend/vite.config.js b/motoko/vetkeys/basic_vetkd/frontend/vite.config.js index 6fc36eee1b..7763e05fef 100644 --- a/motoko/vetkeys/basic_vetkd/frontend/vite.config.js +++ b/motoko/vetkeys/basic_vetkd/frontend/vite.config.js @@ -14,11 +14,17 @@ function getDevServerConfig() { stdio: "pipe", }) ); - } catch { - console.error( - `No network running for environment "${ENVIRONMENT}". Start it and deploy first:\n` + - " icp network start -d && icp deploy" - ); + } catch (error) { + if (String(error.stderr).includes("does not contain an environment named")) { + console.error( + `Unknown environment "${ENVIRONMENT}". Check ICP_ENVIRONMENT against the environments in icp.yaml.` + ); + } else { + console.error( + `No network running for environment "${ENVIRONMENT}". Start it and deploy first:\n` + + ` icp network start -d -e ${ENVIRONMENT} && icp deploy -e ${ENVIRONMENT}` + ); + } process.exit(1); } diff --git a/motoko/vetkeys/password_manager_with_metadata/frontend/vite.config.js b/motoko/vetkeys/password_manager_with_metadata/frontend/vite.config.js index a0f092a005..b37e530972 100644 --- a/motoko/vetkeys/password_manager_with_metadata/frontend/vite.config.js +++ b/motoko/vetkeys/password_manager_with_metadata/frontend/vite.config.js @@ -18,11 +18,17 @@ function getDevServerConfig() { stdio: "pipe", }) ); - } catch { - console.error( - `No network running for environment "${ENVIRONMENT}". Start it and deploy first:\n` + - " icp network start -d && icp deploy" - ); + } catch (error) { + if (String(error.stderr).includes("does not contain an environment named")) { + console.error( + `Unknown environment "${ENVIRONMENT}". Check ICP_ENVIRONMENT against the environments in icp.yaml.` + ); + } else { + console.error( + `No network running for environment "${ENVIRONMENT}". Start it and deploy first:\n` + + ` icp network start -d -e ${ENVIRONMENT} && icp deploy -e ${ENVIRONMENT}` + ); + } process.exit(1); } diff --git a/motoko/who_am_i/src/frontend/vite.config.js b/motoko/who_am_i/src/frontend/vite.config.js index 0e18d9ab02..46d000e42b 100644 --- a/motoko/who_am_i/src/frontend/vite.config.js +++ b/motoko/who_am_i/src/frontend/vite.config.js @@ -15,11 +15,17 @@ function getDevServerConfig() { stdio: "pipe", }) ); - } catch { - console.error( - `No network running for environment "${ENVIRONMENT}". Start it and deploy first:\n` + - " icp network start -d && icp deploy" - ); + } catch (error) { + if (String(error.stderr).includes("does not contain an environment named")) { + console.error( + `Unknown environment "${ENVIRONMENT}". Check ICP_ENVIRONMENT against the environments in icp.yaml.` + ); + } else { + console.error( + `No network running for environment "${ENVIRONMENT}". Start it and deploy first:\n` + + ` icp network start -d -e ${ENVIRONMENT} && icp deploy -e ${ENVIRONMENT}` + ); + } process.exit(1); } diff --git a/rust/daily_planner/frontend/vite.config.js b/rust/daily_planner/frontend/vite.config.js index 3cabb9b717..e62b05d93d 100644 --- a/rust/daily_planner/frontend/vite.config.js +++ b/rust/daily_planner/frontend/vite.config.js @@ -15,11 +15,17 @@ function getDevServerConfig() { stdio: "pipe", }) ); - } catch { - console.error( - `No network running for environment "${ENVIRONMENT}". Start it and deploy first:\n` + - " icp network start -d && icp deploy" - ); + } catch (error) { + if (String(error.stderr).includes("does not contain an environment named")) { + console.error( + `Unknown environment "${ENVIRONMENT}". Check ICP_ENVIRONMENT against the environments in icp.yaml.` + ); + } else { + console.error( + `No network running for environment "${ENVIRONMENT}". Start it and deploy first:\n` + + ` icp network start -d -e ${ENVIRONMENT} && icp deploy -e ${ENVIRONMENT}` + ); + } process.exit(1); } diff --git a/rust/evm_block_explorer/frontend/vite.config.js b/rust/evm_block_explorer/frontend/vite.config.js index 4e04e937b5..75825dac6d 100644 --- a/rust/evm_block_explorer/frontend/vite.config.js +++ b/rust/evm_block_explorer/frontend/vite.config.js @@ -15,11 +15,17 @@ function getDevServerConfig() { stdio: "pipe", }) ); - } catch { - console.error( - `No network running for environment "${ENVIRONMENT}". Start it and deploy first:\n` + - " icp network start -d && icp deploy" - ); + } catch (error) { + if (String(error.stderr).includes("does not contain an environment named")) { + console.error( + `Unknown environment "${ENVIRONMENT}". Check ICP_ENVIRONMENT against the environments in icp.yaml.` + ); + } else { + console.error( + `No network running for environment "${ENVIRONMENT}". Start it and deploy first:\n` + + ` icp network start -d -e ${ENVIRONMENT} && icp deploy -e ${ENVIRONMENT}` + ); + } process.exit(1); } diff --git a/rust/face-recognition/frontend/vite.config.js b/rust/face-recognition/frontend/vite.config.js index b85659cc7f..c0f5f4f211 100644 --- a/rust/face-recognition/frontend/vite.config.js +++ b/rust/face-recognition/frontend/vite.config.js @@ -14,11 +14,17 @@ function getDevServerConfig() { stdio: "pipe", }) ); - } catch { - console.error( - `No network running for environment "${ENVIRONMENT}". Start it and deploy first:\n` + - " icp network start -d && icp deploy" - ); + } catch (error) { + if (String(error.stderr).includes("does not contain an environment named")) { + console.error( + `Unknown environment "${ENVIRONMENT}". Check ICP_ENVIRONMENT against the environments in icp.yaml.` + ); + } else { + console.error( + `No network running for environment "${ENVIRONMENT}". Start it and deploy first:\n` + + ` icp network start -d -e ${ENVIRONMENT} && icp deploy -e ${ENVIRONMENT}` + ); + } process.exit(1); } diff --git a/rust/flying_ninja/frontend/vite.config.js b/rust/flying_ninja/frontend/vite.config.js index 8cc5533817..a9edbaa764 100644 --- a/rust/flying_ninja/frontend/vite.config.js +++ b/rust/flying_ninja/frontend/vite.config.js @@ -15,11 +15,17 @@ function getDevServerConfig() { stdio: "pipe", }) ); - } catch { - console.error( - `No network running for environment "${ENVIRONMENT}". Start it and deploy first:\n` + - " icp network start -d && icp deploy" - ); + } catch (error) { + if (String(error.stderr).includes("does not contain an environment named")) { + console.error( + `Unknown environment "${ENVIRONMENT}". Check ICP_ENVIRONMENT against the environments in icp.yaml.` + ); + } else { + console.error( + `No network running for environment "${ENVIRONMENT}". Start it and deploy first:\n` + + ` icp network start -d -e ${ENVIRONMENT} && icp deploy -e ${ENVIRONMENT}` + ); + } process.exit(1); } diff --git a/rust/hello_world/frontend/vite.config.js b/rust/hello_world/frontend/vite.config.js index b85659cc7f..c0f5f4f211 100644 --- a/rust/hello_world/frontend/vite.config.js +++ b/rust/hello_world/frontend/vite.config.js @@ -14,11 +14,17 @@ function getDevServerConfig() { stdio: "pipe", }) ); - } catch { - console.error( - `No network running for environment "${ENVIRONMENT}". Start it and deploy first:\n` + - " icp network start -d && icp deploy" - ); + } catch (error) { + if (String(error.stderr).includes("does not contain an environment named")) { + console.error( + `Unknown environment "${ENVIRONMENT}". Check ICP_ENVIRONMENT against the environments in icp.yaml.` + ); + } else { + console.error( + `No network running for environment "${ENVIRONMENT}". Start it and deploy first:\n` + + ` icp network start -d -e ${ENVIRONMENT} && icp deploy -e ${ENVIRONMENT}` + ); + } process.exit(1); } diff --git a/rust/image-classification/frontend/vite.config.js b/rust/image-classification/frontend/vite.config.js index b85659cc7f..c0f5f4f211 100644 --- a/rust/image-classification/frontend/vite.config.js +++ b/rust/image-classification/frontend/vite.config.js @@ -14,11 +14,17 @@ function getDevServerConfig() { stdio: "pipe", }) ); - } catch { - console.error( - `No network running for environment "${ENVIRONMENT}". Start it and deploy first:\n` + - " icp network start -d && icp deploy" - ); + } catch (error) { + if (String(error.stderr).includes("does not contain an environment named")) { + console.error( + `Unknown environment "${ENVIRONMENT}". Check ICP_ENVIRONMENT against the environments in icp.yaml.` + ); + } else { + console.error( + `No network running for environment "${ENVIRONMENT}". Start it and deploy first:\n` + + ` icp network start -d -e ${ENVIRONMENT} && icp deploy -e ${ENVIRONMENT}` + ); + } process.exit(1); } diff --git a/rust/llm_chatbot/frontend/vite.config.js b/rust/llm_chatbot/frontend/vite.config.js index 468af6aaaa..da95039aa5 100644 --- a/rust/llm_chatbot/frontend/vite.config.js +++ b/rust/llm_chatbot/frontend/vite.config.js @@ -15,11 +15,17 @@ function getDevServerConfig() { stdio: "pipe", }) ); - } catch { - console.error( - `No network running for environment "${ENVIRONMENT}". Start it and deploy first:\n` + - " icp network start -d && icp deploy" - ); + } catch (error) { + if (String(error.stderr).includes("does not contain an environment named")) { + console.error( + `Unknown environment "${ENVIRONMENT}". Check ICP_ENVIRONMENT against the environments in icp.yaml.` + ); + } else { + console.error( + `No network running for environment "${ENVIRONMENT}". Start it and deploy first:\n` + + ` icp network start -d -e ${ENVIRONMENT} && icp deploy -e ${ENVIRONMENT}` + ); + } process.exit(1); } diff --git a/rust/qrcode/frontend/vite.config.js b/rust/qrcode/frontend/vite.config.js index 26a82aaec9..c2d473eec3 100644 --- a/rust/qrcode/frontend/vite.config.js +++ b/rust/qrcode/frontend/vite.config.js @@ -14,11 +14,17 @@ function getDevServerConfig() { stdio: "pipe", }) ); - } catch { - console.error( - `No network running for environment "${ENVIRONMENT}". Start it and deploy first:\n` + - " icp network start -d && icp deploy" - ); + } catch (error) { + if (String(error.stderr).includes("does not contain an environment named")) { + console.error( + `Unknown environment "${ENVIRONMENT}". Check ICP_ENVIRONMENT against the environments in icp.yaml.` + ); + } else { + console.error( + `No network running for environment "${ENVIRONMENT}". Start it and deploy first:\n` + + ` icp network start -d -e ${ENVIRONMENT} && icp deploy -e ${ENVIRONMENT}` + ); + } process.exit(1); } diff --git a/rust/vetkeys/basic_vetkd/frontend/vite.config.js b/rust/vetkeys/basic_vetkd/frontend/vite.config.js index 6fc36eee1b..7763e05fef 100644 --- a/rust/vetkeys/basic_vetkd/frontend/vite.config.js +++ b/rust/vetkeys/basic_vetkd/frontend/vite.config.js @@ -14,11 +14,17 @@ function getDevServerConfig() { stdio: "pipe", }) ); - } catch { - console.error( - `No network running for environment "${ENVIRONMENT}". Start it and deploy first:\n` + - " icp network start -d && icp deploy" - ); + } catch (error) { + if (String(error.stderr).includes("does not contain an environment named")) { + console.error( + `Unknown environment "${ENVIRONMENT}". Check ICP_ENVIRONMENT against the environments in icp.yaml.` + ); + } else { + console.error( + `No network running for environment "${ENVIRONMENT}". Start it and deploy first:\n` + + ` icp network start -d -e ${ENVIRONMENT} && icp deploy -e ${ENVIRONMENT}` + ); + } process.exit(1); } diff --git a/rust/vetkeys/password_manager_with_metadata/frontend/vite.config.js b/rust/vetkeys/password_manager_with_metadata/frontend/vite.config.js index a0f092a005..b37e530972 100644 --- a/rust/vetkeys/password_manager_with_metadata/frontend/vite.config.js +++ b/rust/vetkeys/password_manager_with_metadata/frontend/vite.config.js @@ -18,11 +18,17 @@ function getDevServerConfig() { stdio: "pipe", }) ); - } catch { - console.error( - `No network running for environment "${ENVIRONMENT}". Start it and deploy first:\n` + - " icp network start -d && icp deploy" - ); + } catch (error) { + if (String(error.stderr).includes("does not contain an environment named")) { + console.error( + `Unknown environment "${ENVIRONMENT}". Check ICP_ENVIRONMENT against the environments in icp.yaml.` + ); + } else { + console.error( + `No network running for environment "${ENVIRONMENT}". Start it and deploy first:\n` + + ` icp network start -d -e ${ENVIRONMENT} && icp deploy -e ${ENVIRONMENT}` + ); + } process.exit(1); } diff --git a/rust/who_am_i/src/frontend/vite.config.js b/rust/who_am_i/src/frontend/vite.config.js index 0e18d9ab02..46d000e42b 100644 --- a/rust/who_am_i/src/frontend/vite.config.js +++ b/rust/who_am_i/src/frontend/vite.config.js @@ -15,11 +15,17 @@ function getDevServerConfig() { stdio: "pipe", }) ); - } catch { - console.error( - `No network running for environment "${ENVIRONMENT}". Start it and deploy first:\n` + - " icp network start -d && icp deploy" - ); + } catch (error) { + if (String(error.stderr).includes("does not contain an environment named")) { + console.error( + `Unknown environment "${ENVIRONMENT}". Check ICP_ENVIRONMENT against the environments in icp.yaml.` + ); + } else { + console.error( + `No network running for environment "${ENVIRONMENT}". Start it and deploy first:\n` + + ` icp network start -d -e ${ENVIRONMENT} && icp deploy -e ${ENVIRONMENT}` + ); + } process.exit(1); }