Quantum Mechanics (2nd Edition) by Bransden and Joachain contains the following passage:
Substituting (8.176) into (8.171), we obtain for $S(x)$ the equation $$-\frac{i\hbar}{2m}\frac{\mathrm{d}^2S(x)}{\mathrm{d}x^2} + \frac{1}{2}\biggl[\frac{\mathrm{d}S(x)}{\mathrm{d}x}\biggr]^2 + V(x) - E = 0.$$ So far, no approximation has been made, this equation being strictly equivalent to the original Schrödinger equation (8.171). Unfortunately, equation 8.177) is a non-linear equation which is in fact more complicated than (8.171) itself! We must therefore try to solve (8.177) approximately. To this end, we first remark that if the potential is constant then $S(x) = \pm p_0 x$ (see (8.172)) and the first term on the left of (8.177) vanishes. Moreover, this term is proportional to $\hbar$, and hence vanishes in the classical limit ($\hbar\to 0$). This suggests that we treat $\hbar$ as a parameter of smallness and expand the function $S(x)$ in the power series $$S(x) = S_0(x) + \hbar S_1(x) + \frac{\hbar^2}{2}S_2(x) + \cdots\tag{8.178}$$ Inserting the expansion (8.178) into (8.177) and equating to zero the coefficients of each power of $\hbar$ separately, we find the set of equations $$\begin{align} \frac{1}{2m}\biggl[\frac{\mathrm{d}S_0(x)}{\mathrm{d}x}\biggr]^2 + V(x) - E &= 0\tag{8.179a} \\ \frac{\mathrm{d}S_0(x)}{\mathrm{d}x}\frac{\mathrm{d}S_1(x)}{\mathrm{d}x} - \frac{i}{2}\frac{\mathrm{d}^2 S_0(x)}{\mathrm{d}x^2} &= 0\tag{8.179b} \\ \frac{\mathrm{d}S_0(x)}{\mathrm{d}x}\frac{\mathrm{d}S_2(x)}{\mathrm{d}x} + \biggl[\frac{\mathrm{d}S_1(x)}{\mathrm{d}x}\biggr]^2 - i\frac{\mathrm{d}^2 S_1(x)}{\mathrm{d}x^2} &= 0\tag{8.179c} \end{align}$$
My question is, why does each term have to be zero?
The equation (8.177) is equal to zero. After inserting (8.178) to (8.177). It does not mean each term of order of $\hbar$ have to equal zero since $\hbar$ is constant, does it?