# Custom build step fails with dfx 14

**URL:** <https://forum.dfinity.org/t/custom-build-step-fails-with-dfx-14/22121>\
**Category:** Motoko\
**Created:** [August 14, 2023, 9:38am UTC](https://forum.dfinity.org/t/custom-build-step-fails-with-dfx-14/22121 "2023-08-14T09:38:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ZhenyaUsenko](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/zhenyausenko/32/12200_2.png) [@ZhenyaUsenko](https://forum.dfinity.org/u/ZhenyaUsenko)\
**Post date:** [August 14, 2023, 9:38am UTC](https://forum.dfinity.org/t/custom-build-step-fails-with-dfx-14/22121/1 "2023-08-14T09:38:42Z")

</div>

I’ve been using the next custom **build.sh** script

```auto
#!/bin/sh

CANISTER_NAME=$1
ENTRY_POINT=$2

mkdir -p .dfx/local/canisters/${CANISTER_NAME}

$(vessel bin)/moc ${ENTRY_POINT} -o .dfx/local/canisters/${CANISTER_NAME}/${CANISTER_NAME}.wasm \
-c --debug --idl --stable-types --public-metadata candid:service --actor-idl .dfx/local/canisters/idl/ \
--actor-alias ${CANISTER_NAME} $(dfx canister id ${CANISTER_NAME}) $(vessel sources)

ic-wasm .dfx/local/canisters/${CANISTER_NAME}/${CANISTER_NAME}.wasm -o .dfx/local/canisters/${CANISTER_NAME}/${CANISTER_NAME}.wasm shrink

gzip -f -9 .dfx/local/canisters/${CANISTER_NAME}/${CANISTER_NAME}.wasm

```

And **dfx.json** config

```auto
{
  "canisters": {
    "test": {
      "build": "build.sh test test.mo",
      "candid": ".dfx/local/canisters/test/test.did",
      "type": "custom",
      "wasm": ".dfx/local/canisters/test/test.wasm.gz"
    }
  }
}

```

It works fine with dfx 13.1 and lower but dfx 14 fails with an error

```auto
Failed during wasm installation call: The replica returned a replica error: Replica Error: reject code CanisterError, reject message Wasm module of canister bkyz2-fmaaa-aaaaa-qaaaq-cai is not valid: Failed to decode wasm module: unsupported canister module format, error code None

```

This custom build step serves 2 main purposes: gzip the WASM and install custom Motoko compiler.

The first one is no longer necessary with dfx 14 but, as far as I know, custom build is still the only option to install a different Motoko compiler.

Would appreciate any insight on how I can fix the error.

---

<div class="post-metadata">

**Author:** ![mnl](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/mnl/32/5909_2.png) [@mnl](https://forum.dfinity.org/u/mnl)\
**Post date:** [August 14, 2023, 4:45pm UTC](https://forum.dfinity.org/t/custom-build-step-fails-with-dfx-14/22121/2 "2023-08-14T16:45:06Z")

</div>

> custom build is still the only option to install a different Motoko compiler

you could also use `DFX_MOC_PATH` environment variable, see [docs](https://internetcomputer.org/docs/current/references/cli-reference/dfx-envars#dfx_moc_path)

Perhaps this will help to mitigate the issue?

---

<div class="post-metadata">

**Author:** ![ZhenyaUsenko](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/zhenyausenko/32/12200_2.png) [@ZhenyaUsenko](https://forum.dfinity.org/u/ZhenyaUsenko)\
**Post date:** [August 15, 2023, 11:02am UTC](https://forum.dfinity.org/t/custom-build-step-fails-with-dfx-14/22121/3 "2023-08-15T11:02:36Z")

</div>

It can work as an intermediate solution until we can find a valid fix for this. It adds manual steps to the process that, in my opinion, should be automatic. Complicates deployment of the project for other developers (as they would need to know additional variables to specify instead of just printing “dfx deploy” / “dfx build”).

Ultimately, I would really appreciate an ability to specify moc path in dfx.json config instead of using environment variables (including the ability to specify commands for execution - like “vessel bin” which will handle compiler installation on top of returning a path string).

For now I am manually replacing compiler files in the dfx cache directory and trying to make my custom build work.
