PurposeThis study aims at the sudden outbreak of COVID-19, which had an unprecedented negative impact on the Chinese economy, with firms being affected most. Firms differ in terms of their specific internal environment, shaping their ability to respond to the outbreak, so the impact may also vary.Design/methodology/approachIn this paper Chinese listed firms are selected as samples to investigate the mediating effect of prior digital technology on the relationship between R&D (research and development) investment (funds and staff) and firm performance during the epidemic. Firm size and diversification are then introduced as moderating variables to explore the conditional mediating effect of digital technology.FindingsThe results indicate that the higher the firm's prior R&D investment, the higher its digital technology level, and thus the stronger its resistance to the epidemic. Moreover, compared with large-scale firms, small-scale firms have the advantage of strategic flexibility to technological changes, which can help them accumulate experience from R&D activities for digital transformation, thus attenuating the negative impact of the COVID-19 on firm performance. Finally, the results also show that digital technology mediates more strongly between R&D investment and firm performance in diversified firms than in centralized firms.Originality/valueThe study builds a mediation model to reveal the process mechanism through which R&D investment affects firm performance via digital technology. Firm size and diversification are then innovatively introduced as situational factors to build the moderated mediation model, which opens up a new perspective for understanding the effect of firm internal factors on the relationship between R&D investment, digital transformation and firm performance.