What should we do if we find an anticipation effect in difference-in-differences? When using a difference-in-differences estimator, one key assumption is the absence of anticipation, meaning that the real event date shouldn't be a couple of years before the real event year (yearly data). I am wondering what should we do if we test for this and find out that the data violated the "no anticipation effect" assumption?

It's difficult to offer specific advice without knowing more about your treatment. I assume this new law/policy is rolled in some staggered fashion, and that once treatment is in place it never reverses. In other words, once you're treated you're treated forever. A plethora of new literature is now widely available to handle settings where you have multiple time periods and variation in treatment timing. Peruse the did reference manual for a specific use case in R.
In my opinion, anticipation isn't fatal. As indicated in the comments, the new law was heavily advertised in the media. We might suspect some anticipatory response as we approach the enactment date. As a clever hack, define the anticipation period as the actual treatment epoch. For example, suppose a controversial state law/policy was introduced in the year 2020 in one region of the United States. In 2019, strong media interest results in behavioral change before the actual law goes into effect. Instead of defining "post-treatment" as all periods (years) from 2020 onward, you'd now define 2019 at the first post-treatment year. In other words, you can circumvent concerns related to anticipation by redefining "treatment" to include the periods when anticipation begins.
Be advised that as a work-around in difference-in-differences applications, this technique may require strengthening other assumptions. In my opinion, redefining the treatment epoch in this manner is usually limited to the period(s) immediately adjacent to the treatment epoch. Using more distant pre-periods may invite skepticism, suggesting trends were not so parallel in the periods before the onset of treatment.
I often find it more difficult to buttress claims of a common trend before some shock when faced with anticipatory concerns. If anticipation is strongly suspected, then you should try to demonstrate, to some degree, a trend equivalence even before this anticipation period. This is challenging, if not impossible, without serial observations pre-treatment.
