Imagine a space ship in S frame moving with speed v (in the x direction) relative to S'. An astronaut on board shines a light from the the rear of the spacecraft to the front (along the x-direction). The astronaut measures the time taken for the light to reach the other end to be T. The proper length of the spacecraft is L.
The astronaut would then determine the speed of light to be:
$$c = L/T\tag{1}$$
From the S' frame, a stationary observer would measure the length of the spacecraft to be:
$$l' = L/\gamma$$
Then the total distance travelled by the light ray would be:
$$d = vt' + l' = vT\gamma + L/\gamma$$
This is because the light ray would have to traverse the contracted length of the spacecraft ($l'$), but also cover the additional distance that the craft has moved from the starting point ($vt'$) as seen from the $S'$ frame.
and $d$ would also be:
$$d = ct' = cT\gamma$$
which leads to $$ cT\gamma = vT\gamma + L/\gamma$$
from which follows $$c = (1/\gamma^2)(L/T) + vT\gamma\tag{2}$$
Now, if we compare equations $(1)$ and $(2)$ we would find that the two observers would disagree on the speed of light.
So, my question is where has this argument gone wrong?
My first thoughts would be that it is incorrect to just simply add on the extra distance that the spacecraft travels to the total distance measured from $S'$, but I can't seem to understand why that would be the case.