# How to deal without DFX?

**URL:** <https://forum.dfinity.org/t/how-to-deal-without-dfx/28701>\
**Category:** Motoko\
**Created:** [March 21, 2024, 6:10am UTC](https://forum.dfinity.org/t/how-to-deal-without-dfx/28701 "2024-03-21T06:10:29Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![qwertytrewq](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/qwertytrewq/32/10423_2.png) [@qwertytrewq](https://forum.dfinity.org/u/qwertytrewq)\
**Post date:** [March 21, 2024, 6:10am UTC](https://forum.dfinity.org/t/how-to-deal-without-dfx/28701/1 "2024-03-21T06:10:29Z")

</div>

I am very much pissed off calling DFX that compiles not only what I need to compiler but also I don’t need to compile and when I don’t want to compile anything (e.g. I can’t turn off recompiling everything when I run `dfx generate`), inflating compilation times to giant amounts.

We should use normal Makefile workflow, DFX needs to be excluded.

I want to write a Makefile. But how to do `dfx generate` without DFX? Does DFX call something to do `dfx generate` or is it a built-in DFX functionality?

---

<div class="post-metadata">

**Author:** ![frederikrothenberger](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/frederikrothenberger/32/3826_2.png) [@frederikrothenberger](https://forum.dfinity.org/u/frederikrothenberger)\
**Post date:** [March 21, 2024, 8:21am UTC](https://forum.dfinity.org/t/how-to-deal-without-dfx/28701/2 "2024-03-21T08:21:35Z")

</div>

Hi @qwertytrewq

`didc` is the tool that generates the bindings, and it is available standalone from the candid repository [here](https://github.com/dfinity/candid) ([latest release](https://github.com/dfinity/candid/releases/tag/2024-02-27)). You can generate bindings by calling `didc bind`.

* * *

Having said that, did you present your feedback of what exactly should be improved about `dfx` somewhere? I’m sure the SDK team would be interested.

While `dfx` is definitely not perfect, it can be improved. IMHO the better solution is to improve `dfx` such that you don’t have to use `didc` directly. There is also [a feedback board](https://dx.internetcomputer.org), which would probably be the best place to request improvements.

---

<div class="post-metadata">

**Author:** ![qwertytrewq](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/qwertytrewq/32/10423_2.png) [@qwertytrewq](https://forum.dfinity.org/u/qwertytrewq)\
**Post date:** [March 21, 2024, 8:35am UTC](https://forum.dfinity.org/t/how-to-deal-without-dfx/28701/3 "2024-03-21T08:35:57Z")

</div>

`dfx` recompiles everything when I request it to do something, e.g. to `generate`. This takes a lot of time.

Also, if I want to recompile a canister, I need to recompile all canisters, because otherwise canisters other than our dependencies become missing in `.env` (at least so it was with a previous version of DFX).

Compiling a big project is almost a nightmare due to these “features” causing outspoken slowness of compiling.

Should I copy this to the feedback board?

---

<div class="post-metadata">

**Author:** ![frederikrothenberger](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/frederikrothenberger/32/3826_2.png) [@frederikrothenberger](https://forum.dfinity.org/u/frederikrothenberger)\
**Post date:** [March 21, 2024, 9:33am UTC](https://forum.dfinity.org/t/how-to-deal-without-dfx/28701/4 "2024-03-21T09:33:15Z")

</div>

> Should I copy this to the feedback board?

Thanks @qwertytrewq. Yes, I think that’s the right way to go.

@Vivienne: do you agree?

---

<div class="post-metadata">

**Author:** ![Vivienne](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/vivienne/32/29170_2.png) [@Vivienne](https://forum.dfinity.org/u/Vivienne)\
**Post date:** [March 21, 2024, 10:59am UTC](https://forum.dfinity.org/t/how-to-deal-without-dfx/28701/5 "2024-03-21T10:59:01Z")

</div>

Thanks for voicing your frustrations, we don’t get enough feedback about such usability issues with dfx. And please add it to the feedback board!

dfx builds Motoko canisters (but not others) as part of `dfx generate` because it is the only canister type that doesn’t force the user to specify a `.did` file. As a result if `dfx generate` wouldn’t build the canister (read: the did file) automatically, then

- `dfx generate` would fail if the user did not `dfx build` some time before because the did file is missing
- IMO more importantly: `dfx generate` would produce the wrong bindings if method signatures changed between the last `dfx build` and running `dfx generate`, resulting in errors that would be pretty hard to debug for non-experts

I’m personally not a fan of not automatically building because of the second point, but if you disagree please explain. It would be possible to add a flag like `--no-build` to `dfx generate`, but honest question: would you have found out about that flag? E.g. with `dfx generate --help`? I never know how reliably people check documentation

> [@qwertytrewq](#):
>
> if I want to recompile a canister, I need to recompile all canisters, because otherwise canisters other than our dependencies become missing in `.env` (at least so it was with a previous version of DFX).

That shouldn’t be necessary if you declare the `canisters.<canister>.dependencies` key in dfx.json properly

---

<div class="post-metadata">

**Author:** ![bitdivine](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/bitdivine/32/246_2.png) [@bitdivine](https://forum.dfinity.org/u/bitdivine)\
**Post date:** [March 22, 2024, 2:18pm UTC](https://forum.dfinity.org/t/how-to-deal-without-dfx/28701/6 "2024-03-22T14:18:20Z")

</div>

We use didc directly for the nns-dapp and sns-aggregator. It works well in standalone mode, for our purposes anyway. It has needed some tweaks but the team that maintains it has been very helpful at getting things fixed.

---

<div class="post-metadata">

**Author:** ![qwertytrewq](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/qwertytrewq/32/10423_2.png) [@qwertytrewq](https://forum.dfinity.org/u/qwertytrewq)\
**Post date:** [March 31, 2024, 2:31pm UTC](https://forum.dfinity.org/t/how-to-deal-without-dfx/28701/7 "2024-03-31T14:31:12Z")

</div>

`dfx generate` produced several files per actor, as:

```plaintext
example_backend.did.d.ts example_backend.did.js index.d.ts index.js

```

But

```shell
didc bind -t ts XXX.did

```

outputs only one file (to stdout).

How to create the same several files as `dfx generate` produced?

---

<div class="post-metadata">

**Author:** ![bitdivine](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/bitdivine/32/246_2.png) [@bitdivine](https://forum.dfinity.org/u/bitdivine)\
**Post date:** [April 3, 2024, 9:15am UTC](https://forum.dfinity.org/t/how-to-deal-without-dfx/28701/8 "2024-04-03T09:15:10Z")

</div>

I am afraid I have no idea. Does it help to run `-t ts` and `-t js`? I’m not a front end guy so I typically have to stare at those files to figure out what on an earth they contain. 😅 Maybe @lmuntaner can help?

---

<div class="post-metadata">

**Author:** ![dfx-json](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/dfx-json/32/4784_2.png) [@dfx-json](https://forum.dfinity.org/u/dfx-json)\
**Post date:** [April 4, 2024, 10:51pm UTC](https://forum.dfinity.org/t/how-to-deal-without-dfx/28701/9 "2024-04-04T22:51:44Z")

</div>

If you take a look at [https://internetcomputer.org/docs/current/developer-docs/developer-tools/cli-tools/dfx-json-reference](https://internetcomputer.org/docs/current/developer-docs/developer-tools/cli-tools/dfx-json-reference), and specifically `CanisterDeclarationsConfig`, it states

```auto
A list of languages to generate type declarations. Supported options are 'js', 'ts', 'did', 'mo'. Default is ['js', 'ts', 'did']

```

dfx reads the canisters in your project from `dfx.json` and then, by default, uses `didc` to generate bindings for JavaScript, TypeScript, and Candid

---

<div class="post-metadata">

**Author:** ![anon74414410](https://avatars.discourse-cdn.com/v4/letter/a/85f322/32.png) [@anon74414410](https://forum.dfinity.org/u/anon74414410)\
**Post date:** [April 4, 2024, 11:07pm UTC](https://forum.dfinity.org/t/how-to-deal-without-dfx/28701/10 "2024-04-04T23:07:04Z")

</div>

All you strictly need is the `idlFactory`. `dfx` creates the index as a helper, but you’ve clearly progressed beyond the beginner use case it’s suited for. Just write your own `createActor` method and import the `idlFactory` from

```auto
didc bind -t js XXX.did

```

---

<div class="post-metadata">

**Author:** ![qwertytrewq](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/qwertytrewq/32/10423_2.png) [@qwertytrewq](https://forum.dfinity.org/u/qwertytrewq)\
**Post date:** [April 6, 2024, 9:31am UTC](https://forum.dfinity.org/t/how-to-deal-without-dfx/28701/11 "2024-04-06T09:31:31Z")

</div>

I do like:

```motoko
import { idlFactory as mainIdlFactory, ZonBackend } from "../../out/src/backend/main";
...
const MainCanister: ZonBackend = Actor.createActor(mainIdlFactory, {canisterId: process.env.CANISTER_ID_MAIN!})

```

and get:

```plaintext
Uncaught (in promise) TypeError: interfaceFactory is not a function
    at Actor.createActorClass (actor.js:111:1)
    at Actor.createActor (actor.js:137:1)
    at App.tsx:58:39

```

What do I do wrong?

---

<div class="post-metadata">

**Author:** ![qwertytrewq](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/qwertytrewq/32/10423_2.png) [@qwertytrewq](https://forum.dfinity.org/u/qwertytrewq)\
**Post date:** [April 6, 2024, 10:02am UTC](https://forum.dfinity.org/t/how-to-deal-without-dfx/28701/12 "2024-04-06T10:02:40Z")

</div>

Solved by generating both `.js` and `.d.ts` files.

---

<div class="post-metadata">

**Author:** ![Infeelit](https://avatars.discourse-cdn.com/v4/letter/i/a9adbd/32.png) [@Infeelit](https://forum.dfinity.org/u/Infeelit)\
**Post date:** [April 6, 2024, 12:15pm UTC](https://forum.dfinity.org/t/how-to-deal-without-dfx/28701/13 "2024-04-06T12:15:25Z")

</div>

Makefiles can give you more control. To skip DFX for generating, check its documentation or source code to find the command it uses internally. Then, call that command directly in your Makefile.
