Issue first raised in Stack repository, see commercialhaskell/stack#5851. The suggested workaround in the exception message is not a workaround.
On Windows, the command stack build +RTS --io-manager=native -RTS results in the display of the MigrationFailure PantryException
Encountered error while migrating Pantry database:
\\.\NUL: hDuplicateTo: illegal operation (handles are incompatible)
Please report this on https://github.com/commercialhaskell/stack/issues
As a workaround you may delete Pantry database in C:\sr\pantry\pantry.sqlite3 triggering its recreation.
This is arising from the Pantry.Storage.initStorage (a wrapper around Pantry.Storage.SQLite.initStorage) in Pantry.withPantryConfig. (Stack uses withPantryConfig in Stack.Config.configFromConfigMonoid.) I am still investigating.