We report on a simultaneous near-infrared, optical, and X-ray campaign performed in 2017 with the XMM-Newton and Swift satellites and the HAWK-I instrument mounted on the Very Large Telescope (VLT) on the transitional millisecond pulsar PSR J1023+0038. Near-infrared observations were performed in fast-photometric mode (0.5 s exposure time) in order to detect any fast variation of the flux and correlate this with the optical and X-ray light curves. The optical light curve shows the typical sinusoidal modulation at the system orbital period (4.75 h). No significant flaring or flickering is found in the optical, nor any signs of transitions between active and passive states. On the contrary, the near-infrared light curve displays a bimodal behaviour, showing strong flares in the first part of the curve, and an almost flat trend in the rest. The X-ray light curves instead show a few low-high mode transitions, but no flaring activity is detected. Interestingly, one of the low-high mode transitions occurs at the same time as the emission of an infrared flare. This can be interpreted in terms of the emission of an outflow or a jet: the infrared flare could be due to the evolving spectrum of the jet, which possesses a break frequency that moves from higher (near-infrared) to lower (radio) frequencies after the launching, which has to occur at the low-high mode transition. We also present the cross-correlation function between the optical and near-infrared curves. The near.infrared curve is bimodal, therefore we divided it into two parts (flaring and quiet). While the cross-correlation function of the quiet part is found to be flat, the function that refers to the flaring part shows a narrow peak at ̃10 s, which indicates a delay of the near-infrared emission with respect to the optical. This lag can be interpreted as reprocessing of the optical emission at the light cylinder radius with a stream of matter spiraling around the system due to a phase of radio ejection. This strongly supports a different origin of the infrared flares that are observed for PSR J1023+0038 with respect to the optical and X-ray flaring activity that has been reported in other works on the same source.