/execute as @e[type=!player] if entity @e[type=villager,nbt={NoAI:1},distance=..2] run effect give @e[type=villager,nbt={NoAI:1},distance=..2] minecraft:invisibility 999999 1 true
for some reason it doesn't give an error message but it also doesn't do anything...
The villager was not found, so execution stopped. Be sure to specify the correct data types:
NoAI:1b