Fluxes in heterotic and type II string compactifications