Compiler reference

The Motoko compiler (moc) is the primary tool for compiling Motoko programs into executable WebAssembly (Wasm) modules. The compiler runs in the background when you build projects using the DFINITY Canister SDK. If you invoke the compiler directly on the command-line, you can press CTRL-C to exit.

This section provides compiler command-line reference information.


Use the Motoko compiler (moc) to compile Motoko programs into executable WebAssembly (Wasm) modules.

Basic usage

moc [option] [file ...]


You can use the following options with the moc command.

Option Description


Specifies a path to actor IDL files.


Specifies an actor import alias.

--args <file>

Read additional newline separated command line arguments from <file>

--args0 <file>

Read additional NUL separated command line arguments from <file>


Compiles programs to WebAssembly.


Performs type checking only.


Respects debug expressions in the source (the default).


Dumps parse.


Dumps type-checked AST.


Dumps intermediate representation


Displays detailed error message for syntax errors.


Displays usage information.


Hides compiler warnings.


Treat warnings as errors.


Generates the interface description language specification.


Runs the compiler in an interactive read–eval–print loop (REPL) shell so you can evaluate program execution (implies -r).


Interprets the lowered code.


Outputs a source map.


Disables await-lowering (with -iR).


Disables async-lowering (with -iR).


Skips intermediate code checking.


Disables statically-linked runtime.


Disables system API imports.


Creates an output file.


Sets the print depth.

--package <pkg-name> <pkg-URL>

Specifies a package-name package-URL pair, separated by a space.


Prints the dependencies for a given source file.


Activates profiling counters in interpreters.

--profile-field <field>

Includes the given field from the program result in the profile file.


Sets profiling output file.

--profile-line-prefix <prefix>

Adds the specified prefix string to each profile line.


Interprets programs.


Ignores debug expressions in the source.


Uses the the stub version of the system API.


Activates tracing in interpreters.


Generates verbose output.


Displays version information.


Uses the WASI system API (wasmtime).