See nlmixr2/nlmixr2#253.
Rstan sets some environement variables: PKG_CPPFLAGS, PKG_LIBS and USE_CXX17. These variables interfere with other R packages using R CMD SHLIB, such as nlmixr2, and make them unable to run.
The fix is obvious: rstan should reset these changes after building a model.