Error: Field 'main' is mandatory for canister ***

$ dfx deploy --network=ic
Deploying all canisters.
All canisters have already been created.
Building canisters...
Error: Field 'main' is mandatory for canister test.

code

import Principal "mo:base/Principal";
import Time "mo:base/Time";
actor {
  var nat:Nat = 1;
  public func queryData(): async Nat{
    return nat
  }
}

$ dfx -V
dfx 0.9.3

This error message refers to dfx.json, meaning that you have not told dfx which file to compile if you try to deploy canister ‘test’. Here’s an example for a proper Motoko canister declaration in dfx.json:

"canisters": {
  "hello": {
    "main": "src/hello/main.mo",
    "type": "motoko"
  },
  <other canisters>
}

Note: if you dfx upgrade to a newer version you should get more useful error messages.