Posted in Code Apps

PAC CLI “Environment Not Found” – but the ID was correct?!

I hit a strange issue today while trying to spin up a Power Apps Code App from VS Code.

I was running:

npx power-apps init --display-name "<MY APP NAME>" --environment-id <env-id>

And got this error:

Environment '<env-id>' not found. Please verify the environment ID and ensure you have access to it.
Assertion failed: !(handle->flags & UV_HANDLE_CLOSING)

The confusing part?
– The environment ID was 100% correct
– It was working just a few hours earlier
– No changes on my device like updates or VS Code related changes

Initial troubleshooting

I went through the standard checklist:

  • Re-authenticated PAC CLI (multiple times)
  • Removed and recreated auth profiles
  • Reinstalled the Power Platform VS Code extension
  • Restarted VS Code and device
  • Double-checked PAC CLI version
  • Verified the environment ID
  • Google and AI search – which even pointed out to a known issue on specific PAC CLI versions, however that wasn’t the case for me

Nothing worked 😔

The real issue (multi-tenant gotcha)

After digging a bit deeper, I noticed something:

The Tenant ID was conflicting with my device / Organization Tenant.

  • My Dataverse Environment was in a separate Entra Tenant
  • However, PAC CLI was still authenticating against the corporate tenant (which my device is enrolled to)

So even though the environment ID was valid, it was being resolved in the wrong tenant, so PAC simply couldn’t find it.

Solution

The solution was to explicitly force the tenant during authentication:

pac auth create --tenant <DEV tenant>

After that:

pac auth select --index <profile>

Problem solved, now my pac code push worked just fine.

⚠️ NPX

I also noticed something else along the way.

The official docs often suggest using:

npx power-apps ...

However, this caused inconsistencies for me, especially in a multi-tenant setup.

  • npx
    • Spins up a separate Node process
    • Doesn’t always respect your existing PAC CLI auth context
    • Can default back to your “home” (corporate) tenant
  • pac
    • Uses your configured auth profiles
    • Keeps tenant context consistent
    • More reliable for day-to-day development

TL;DR

If your environment exists but PAC CLI says it doesn’t:

You’re probably in the wrong tenant
Fix it with:

pac auth create --tenant <correct tenant>

Hope this was helpful and keep Power Apps Coding.

Leave a comment