See for eaxmple the Mozilla IRS dispute as an example. Mozilla resolved this by putting their money making endeavors into a for profit org, which is in turn owned by the nonprofit, but the for profit org pays tax on their income.
https://www.irs.gov/charities-non-profits/unrelated-business...
See also