Dfx does not install canisters after clean

For some reason, dfx refuses to clean the state and I cannot reinstall the canisters - i.e. I end up with canisters that are not found.

In a terminal:

❯ sudo rm -r .dfx
❯ dfx start --clean
Running dfx start for version 0.20.0
Using project-specific network 'local' defined in /Users/daviddalbusco/projects/opensource/proposals.network/dfx.json
Initialized replica.
Dashboard: http://localhost:65088/_/dashboard

In another terminal

❯ dfx deploy internet_identity
Deploying: 
All canisters have already been created.
Building canisters...
WARN: .did file for canister 'internet_identity' does not exist.
Installing canisters...
Deployed canisters.
❯ dfx canister call internet_identity init_salt
WARN: DEPRECATION WARNING: Cannot fetch Candid interface from canister metadata, reading Candid interface from the local build artifact. In a future dfx release, we will only read candid interface from canister metadata.
WARN: Please add the following to dfx.json to store local candid file into metadata:
"metadata": [
   {
     "name": "candid:service"
   }
]
WARN: Cannot fetch Candid interface for init_salt, sending arguments with inferred types.
Error: Failed update call.
Caused by: Failed update call.
  The replica returned a rejection error: reject code DestinationInvalid, reject message Canister qhbym-qaaaa-aaaaa-aaafq-cai not found, error code Some("IC0301")

As you can notice in the last error message, the canister is not found. I don’t think it’s related to candid, I got the similar issue for any canisters.

What’s the issue again?

Anyone has an idea?

❯ dfx deploy internet_identity
Deploying: 
All canisters have already been created.
Building canisters...
WARN: .did file for canister 'internet_identity' does not exist.
Installing canisters...
Deployed canisters.

❯ dfx canister delete internet_identity
Deleting canister internet_identity, with canister_id qhbym-qaaaa-aaaaa-aaafq-cai
Error: Failed to delete canister 'internet_identity'.
Caused by: Failed to delete canister 'internet_identity'.
  Failed to delete qhbym-qaaaa-aaaaa-aaafq-cai.
    Failed to call update function 'delete_canister' regarding canister 'qhbym-qaaaa-aaaaa-aaafq-cai'.
      Update call (without wallet) failed.
        The replica returned a rejection error: reject code DestinationInvalid, reject message Canister qhbym-qaaaa-aaaaa-aaafq-cai not found, error code Some("IC0301")

Adding a specific canister ID to deploy a canister locally leads to the error - i.e. leads to not being able to deploy any canister locally anymore.

"satellite": {
			"candid": "candid/satellite.did",
			"type": "custom",
			"wasm": "https://github.com/junobuild/juno/releases/download/v0.0.30/satellite-v0.0.17.wasm.gz",
			"remote": {
				"id": {
					"ic": "gz2uc-6yaaa-aaaal-adgyq-cai",
					"local": "jx5yt-yyaaa-aaaal-abzbq-cai" // <--- adding this line
				}
			}
		}

Removing that line of configuration and deploying the canister manually with a --specified-id parameter resolved the issue. What a waste of time.

Specifying an entry in the “remote” section tells dfx not to deploy the canister on that network (no matter what the network is).

If you’re looking for an equivalent to the --specified-id parameter, but specified in dfx.json, try this:

"satellite": {
			"candid": "candid/satellite.did",
			"type": "custom",
			"wasm": "https://github.com/junobuild/juno/releases/download/v0.0.30/satellite-v0.0.17.wasm.gz",
			"remote": {
				"id": {
					"ic": "gz2uc-6yaaa-aaaal-adgyq-cai"
				}
			},
			"specified_id": "jx5yt-yyaaa-aaaal-abzbq-cai"
		}