Motoko 11 upgrade error (system capability)?

I have

`system` capability required, but not available
 (need an enclosing async expression or function body or explicit `system` type parameter)```
in a library.

Apparently, this error appeared after upgrade to

Motoko compiler 0.11.0+ (source yh3wb1vx-vj8j4j32-k8gq4m8y-4cxlqinf)

It is a stopper for my project.

What is this what to do?

Well, here is my code:

import Cycles "mo:base/ExperimentalCycles";
import Int "mo:base/Int";
import Debug "mo:base/Debug";
import Nat "mo:base/Nat";

module {
    public func topUpCycles(maxCycles: Nat): (accepted : Nat) {
        // Debug.print("maxCycles: " # debug_show(maxCycles) # " Proposed cycles: " # debug_show(Cycles.available()) # " balance: " # debug_show(Cycles.balance()));
        // let amount = Int.min(maxCycles, Int.max(0, Cycles.available() + Cycles.balance()));
        let amount = Int.min(maxCycles, Cycles.available()) - Cycles.balance();
        let amount2 = Int.max(amount, 0);
        // Debug.print("Accepting cycles: " # debug_show(amount2));

    public func addPart(maxAmount: Nat) {
        let amount = Nat.min(Cycles.balance() / 2, maxAmount);
        ignore Cycles.accept(amount);
        // Debug.print("adding " # debug_show(amount) # " cycles");

Here is the migration guide for motoko 11

What do you need motoko 11 for?

1 Like

I would also recommend changing your title to something along the lines of ‘motoko 11 upgrade error’ so when others inevitably run into this problem they can find a solution

1 Like

But after I follow the recommendation:

/home/porton/Projects/nacdb/src/ syntax error [M0001], unexpected token 'system', expected one of token or <phrase> sequence:
  > <pat_plain> <annot_opt> <func_body>
  seplist(<typ_bind>,,) > <pat_plain> <annot_opt> <func_body>

I now have

public func topUpCycles<system>(maxCycles: Nat): (accepted : Nat) {
    // ...

See playground example, file, with dummy call in

Are you getting that error from the motoko compiler or vscode - if the latter the vscode motoko plugin might need updating.

I haven’t updated to Motoko 11 but receive this error warning now for Motoko base@0.10.4?

Is this just a problem with the Motoko plugin then?

Screenshot 2024-03-08 at 1.28.32 p.m.

That’s correct; the VS Code extension is using a built-in type checker for the latest version of the language.

We could add support for multiple compiler versions if there is enough interest, especially given these breaking changes in 0.11.

I ended up downgrading my extension version because it was breaking my project

For anyone reading this who is still on Motoko 0.10, you can downgrade to v0.15.2 of the extension in the VS Code marketplace or using the corresponding GitHub release.

1 Like

As a quick update, the latest version of the extension (v0.16.0) now supports syntax highlighting for the previous version of Motoko (0.10.4) when using dfx 0.17 or earlier.

You can activate this by including the following line in your dfx.json config file:

  "dfx": "0.17.0"

Let me know if you run into any issues, and I’ll do my best to resolve them. Cheers!


Thank you very much @rvanasa!

I installed dfxvm and set dfx 0.17.0 as the default and also added it to my dfx.json. However, I am
getting the same Motoko plugin error as before? Any idea what I need to do to activate the right plugin version?

Motoko plugin error:


Screenshot 2024-03-10 at 9.30.20 p.m.

Solution was to exit and refresh VS code after updating!

1 Like