How to import a canister in a package?

In a package A I have the canister ic_eth (that processes Ethereum transactions) built by dfx.json.
In the same package I have:

import ic_eth "canister:ic_eth";

But when I import this package A in software B:

moc `mops sources` src/storage/CanDBPartition.mo
...
.mops/_github/passport-client-dfinity#v0.1.0@323cf9ce3f5b3b225151870c6eea64e16b4260fc/src/lib/Verifier.mo:13.1-13.32: import error [M0011], canister alias "ic_eth" not defined

even despite the importing project B has ic_eth built through dfx.json, too.

How to rewrite package A for it to work?

I don’t understand how the compiler can output canister alias "ic_eth" not defined when I’ve just successfully build this canister with dfx deploy ic_eth.

Is this how you try to compile your code? Because moc will not try to fetch any information on its own. You need to supply it a lot of extra information. Here’s an example from the default dfx new project when run built with dfx build -vv:

"/Users/ssiff/.cache/dfinity/versions/0.16.1/moc" "/Users/ssiff/Desktop/hello/src/hello_backend/main.mo" "-o" "/Users/ssiff/Desktop/hello/.dfx/local/canisters/hello_backend/hello_backend.wasm" "-c" "--debug" "--idl" "--stable-types" "--public-metadata" "candid:service" "--public-metadata" "candid:args" "--actor-idl" "/Users/ssiff/Desktop/hello/.dfx/local/canisters/idl/" "--actor-alias" "hello_backend" "bkyz2-fmaaa-aaaaa-qaaaq-cai" "--actor-alias" "hello_frontend" "bd3sg-teaaa-aaaaa-qaaba-cai" "--package" "base" "/Users/ssiff/.cache/dfinity/versions/0.16.1/base"

The critical part for you is "--actor-alias" "hello_backend" "bkyz2-fmaaa-aaaaa-qaaaq-cai". If you don’t tell moc about a canister name to id mapping it can’t figure it out on its own. And IIRC this part contains the .did files in the format of <canister id>.did to map the id to an interface: "--actor-idl" "/Users/ssiff/Desktop/hello/.dfx/local/canisters/idl/"