Failed while trying to generate type declarations for 'asset_canister'

I am trying to deploy an asset canister that just holds a bunch of files for my frontend application. However, I want the canister to be seperate from my actual frontend canister.

In my dfx.json I am declaring the asset canister like this:

	"asset_canister": {
		"type": "assets",
		"source": ["./public_assets"]
	},

Where the source is a folder holding the assets (mainly pictures) I would like to host. However, when I first run “dfx deploy” I get the following error:

Error: Failed while trying to generate type declarations for ‘asset_canister’.

Caused by: Candid file: /Users//<my_project>/.dfx/local/canisters/asset_canister/assetstorage.did doesn’t exist.

For privacy purposes I generalized some of the fields in the “Caused by” but you get the idea. The thing is if I run “dfx deploy” a second time, then everything works and it deploys just fine. How can I stop it from erroring out the first deploy though?

If a canister relies on another canister’s .did file I suggest you declare it in the dependencies field in dfx.json. The dfx.json produced by dfx new hello_world has an example

If you have done that already, then it’s probably a bug. We already know about one where the did files are not properly prepared if deploying to --network ic before deploying to local, but I don’t know if that applies to your situation. In my experience, running dfx build --check before the actual deployment usually is a workaround

It should not have to rely on another canisters did file. I am just trying to deploy it as a stand alone asset canister that just hosts some predefined pictures I put in folder “./public_assets”. This is just using the local dfx deploy command btw. My asset canister for my frontend works just fine, its just when I try and declare this separate asset canister I get the error.

I can reproduce the issue and filed a bug (note to self: ticket).

Workaround for now: add "build": "echo 'skip build'" to your asset_canister declaration in dfx.json

1 Like