How to fix "kicad-cli pcb export step" not exporting component 3D models

Problem:

You are trying to export a 3D STEP model of your PCB using a command such as

kicad-cli pcb export step MyPCB.kicad_pcb

but the resulting STEP file is missing all (or almost all) component models (i.e. only the PCB is exported).

Furthermore, in the output of the command, you can read

Cannot add a VRML model to a STEP file.

for every single component, for example

Add component R6.
Cannot add a VRML model to a STEP file.
Add component R21.
Cannot add a VRML model to a STEP file.
Add component C7.
Cannot add a VRML model to a STEP file.
Add component C16.
Cannot add a VRML model to a STEP file.

Solution

Add the --subst-models flag to kicad-cli in order to automatically substitute VRML models with STEP models:

kicad-cli pcb export step MyPCB.kicad_pcb --subst-models

After that, all available component models will be exported just like in the viewer.