I have the very same problem here. Are you running your code sequentially? (Not use any parallelism). I'm pretty sure it is a clash between terraand lidR but I was able to run my code using plan(sequential) instead of plan(multisession).
Did you find a workaround? I tried using library directly into the custom function, but it did not work.
Lilian