ComfyUI Wan 2.2 ‘cannot import name Wan22’ Error: Fix the latent_formats Version Mismatch

The Error That Shows Up Only After an Update

One of the most frustrating ComfyUI failures is the one that appears the moment you think everything got better. You update ComfyUI (or a custom node), reload a workflow that worked yesterday, hit Run, and the sampler dies with a traceback ending in:

!!! Exception during processing !!! cannot import name 'Wan22' from 'comfy.latent_formats'
Traceback (most recent call last):
  ...
ImportError: cannot import name 'Wan22' from 'comfy.latent_formats'

If you search the long tail of this exact string, you’ll find it clustered on the ComfyUI core issue tracker and the ComfyUI-WanVideoWrapper issue tracker. The common thread in nearly every report is the same: the user just updated something. What feels like a random import bug is actually a predictable version mismatch between two pieces of software that are supposed to move together but often don’t.

This article explains exactly what the error means, why it appears after updates, how to diagnose the version drift on your own machine, and the two clean ways to fix it. No masked rewrites, no “just reinstall and pray.” The root cause is small, and once you see it, the fix is mechanical.

What the Error Actually Means

The message is deceptively simple. Python is telling you that some file tried to run this line:

from comfy.latent_formats import Wan22

and that comfy.latent_formats — a module inside the ComfyUI core itself — does not contain a name called Wan22. The error is not saying your model file is corrupt, your VAE is wrong, or your workflow JSON is broken. It is saying the importing code expects a symbol that your specific core build doesn’t ship.

The importer in this case is almost always ComfyUI-WanVideoWrapper, Kijai’s popular package of Wan-specific custom nodes. The wrapper added support for the newer Wan 2.2 latent format relatively early, which meant it began importing Wan22 from the core once the core itself added that class. The wrapper also historically referenced WanVideoRapper (a related latent-format symbol) in its preview code.

The consequence is a classic contract drift:

  • WanVideoWrapper (updated) imports Wan22 from core.
  • ComfyUI core (older) has no Wan22, because native Wan 2.2 support hadn’t landed in that build.
  • Result: ImportError the instant the sampler node executes.

You can think of the wrapper and the core as two sides of a shared interface. Update only one side, and the shared symbol names stop matching. That’s why the error so reliably shows up “right after an update” — because that’s exactly when the two sides get out of step.

Diagnosing the Mismatch on Your Own Machine

Before you change anything, confirm which side drifted. This matters because the fix direction differs depending on what’s actually stale.

Step 1: Read the full traceback, not just the last line

The ImportError line tells you what name is missing, but the traceback frames above it tell you who is importing it. Look for a path like:

File "...\ComfyUI\custom_nodes\ComfyUI-WanVideoWrapper\latent_preview.py", line 8, in <module>
    from comfy.latent_formats import Wan21, Wan22

If the import site points at custom_nodes/ComfyUI-WanVideoWrapper, the wrapper is the importer and the question becomes whether the core is too old. This is the most common situation.

Step 2: Check your ComfyUI core version

Load the ComfyUI UI and look at the version, or run a quick check in the Python environment ComfyUI uses:

cd /path/to/ComfyUI
python -c "import comfy.latent_formats as lf; print(hasattr(lf, 'Wan22'))"

If this prints False, my diagnosis holds: your core predates the Wan22 symbol but your wrapper already references it. If it prints True, the core is fine and you likely have a different local problem (a stale __pycache__, a second ComfyUI install on your PATH, or a wrapper that is itself partially broken).

Step 3: Pin down how the two components update

ComfyUI core and the wrapper update independently. Core updates via git pull, the desktop updater, or update_comfyui.bat on portable. WanVideoWrapper updates through ComfyUI-Manager (or a manual git pull inside its custom_nodes folder). Because neither tool forces the other forward, it’s trivial to end up with a new wrapper and an old core — or the reverse.

The Clean Fix: Align Both Sides

There are two legitimate ways out. Pick based on which side is stale.

Fix A: Update ComfyUI core to a version that ships Wan22

If your wrapper is newer and references Wan22, the correct long-term fix is to bring the core up to a build that includes native Wan 2.2 support. The official ComfyUI Wan 2.2 tutorial is explicit about this: native Wan 2.2 workflows require an up-to-date core, and if nodes or latent formats appear to be missing, your ComfyUI is simply outdated.

# In the ComfyUI repo directory:
git pull
pip install -r requirements.txt

On the portable/desktop builds, use the bundled updater or update/update_comfyui.bat. After the core update, confirm the symbol is present again with the hasattr check from Step 2, then restart ComfyUI fully.

Fix B: Point the wrapper at the version that matches your core

If you must keep an older core (for example, you have another custom node pinned to an older API), align the wrapper downward instead. Check out a wrapper commit that predates its Wan22 import, or roll the whole wrapper back through ComfyUI-Manager to a version contemporary with your core.

What about just deleting the import line?

You’ll see this suggested in threads — editing latent_preview.py to drop Wan22 from the import list. It can unblock a single run, but it’s a band-aid with two real costs. First, it changes the wrapper in a way that will be overwritten on the next node update. Second, it only silences the import; it doesn’t give the wrapper the actual Wan22 logic it wants, so behavior later in the pipeline may be subtly wrong. Treat the line-deletion as a temporary diagnostic, not a permanent state.

Common Pitfalls That Make It Recur

Even after a successful fix, the error can bounce back if you leave these traps in place.

  • Two ComfyUI installations. A lingering old portable/desktop copy on a different drive or PATH will still import the stale latent_formats. Make sure the instance you launch is the one you updated.
  • Stale bytecode. Python caches compiled modules in __pycache__. If imports behave inconsistently after a fix, clear the relevant __pycache__ directories for both the core comfy package and the wrapper, then restart.
  • Half-applied updates. A git pull that errors partway through can leave a mix of old and new files. Re-run it until it reports cleanly, and reinstall requirements.txt afterward.
  • Switching workflows mid-fix. The wrapper error and native-Wan behavior are not always the same root cause. If native workflows work but wrapper workflows freeze (a separate, well-documented issue on the wrapper tracker), the problem may be sampler/offload configuration, not the import. Keep the two symptoms distinct.

This class of error is a cousin of the memory-management regressions we’ve covered before — for example, the pinned-memory OOM that hits Wan and H3 video models and the Dynamic VRAM default that broke workflows. They all share the same signature: a behavior is correct in isolation but breaks when a second moving part changes underneath it.

Verifying the Fix End to End

Don’t trust a green Run; verify the actual points of failure are gone.

  1. Import check. Run the hasattr(lf, 'Wan22') command and confirm it returns True.
  2. Node registration. After restarting ComfyUI, open the node list and confirm the WanVideoWrapper sampler nodes load without errors in the startup log.
  3. Cold run. Load a minimal Wan 2.1 or 2.2 workflow and run the sampler. A successful frame — not just a completed “prompt executed” message but an actual output image/video — is the real acceptance test.
  4. Watch for the sibling symptom. If the import error is gone but generation now hangs at the sampler or OOMs on video, you’ve moved into a different failure class; diagnose model loading and offloading separately rather than re-chasing the import.

Conclusion

The cannot import name 'Wan22' error is not a mysterious bug and not a broken model. It is a version contract between ComfyUI core and the WanVideoWrapper custom node that drifted when only one side was updated. Diagnose it by reading the traceback to find the importer, confirm the core’s Wan22 symbol existence with a one-line check, then align both sides — usually by updating the core to a build with native Wan 2.2 support. Keep the band-aid line-deletion as a diagnostic only, clear stale bytecode, and watch for a second ComfyUI install hiding on your disk. Once both sides speak the same latent_formats vocabulary, the workflow that “suddenly broke” will run again.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *