Type error [M0072], field encodeUtf8 does not exist in type

Good evening,

I’m stuck on the following syntax problem but I can’t find the trick. I tried to get an array of bytes as Nat8 from a Text.

The documentation:

let encodeUtf8 : Text -> Blob

Returns the UTF-8 encoding of the given text

My test snippet:

public func testUtf8() : async Bool {
        let b : Blob = Text.encodeUtf8("FooBär☃");
        //let a : [Nat8] = Blob.toArray(Text.encodeUtf8("FooBär☃"));
        return true;
 };

The error:

type error [M0072], field encodeUtf8 does not exist in type
module {type Pattern = {#char : Char; #predicate : Char → Bool; #text : Text}; compare : (Text, Text) → {#equal; #greater; #less}; compareWith : (Text, Text, (Char, Char) → {#equal; #greater; #less}) → {#equal; #greater; #less}; concat : (Text, Text) → Text; contains : (Text, Pattern) → Bool; endsWith : (Text, Pattern) → Bool; equal : (Text, Text) → Bool; fromChar : Char → Text; fromIter : Iter/1 → Text; greater : (Text, Text) → Bool; greaterOrEqual : (Text, Text) → Bool; hash : Text → Hash; join : (Text, Iter/1) → Text; less : (Text, Text) → Bool; lessOrEqual : (Text, Text) → Bool; map : (Text, Char → Char) → Text; notEqual : (Text, Text) → Bool; replace : (Text, Pattern, Text) → Text; size : Text → Nat; split : (Text, Pattern) → Iter/1; startsWith : (Text, Pattern) → Bool; stripEnd : (Text, Pattern) → ?Text; stripStart : (Text, Pattern) → ?Text; toIter : Text → Iter/1; tokens : (Text, Pattern) → Iter/1; translate : (Text, Char → Text) → Text; trim : (Text, Pattern) → Text; trimEnd : (Text, Pattern) → Text; trimStart : (Text, Pattern) → Text}

Which dfx --version are you using?

That function might be missing from the Motoko base library in the version you’re using. Try the latest sdk:
DFX_VERSION=0.7.0 sh -ci "$(curl -sSL https://sdk.dfinity.org/install.sh)"

1 Like

dfx upgrade
Current version: 0.6.26
Fetching manifest https://sdk.dfinity.org/manifest.json
Already up to date

I checked on github Release dfx-0.6.26 · dfinity/motoko-base · GitHub and yes it doesn’t exist :+1:

But upgrade doesn’t works ?

1 Like

The 0.7.0 release hasn’t been added to the officially supported releases yet, things are still getting lined up with the docs etc. You can install it with the above command though.

1 Like

Be warned, you may need to edit your dfx.json and some front-end files.