The bug is in contextify, and I worked around the problem with the help of this comment:
brianmcd/contextify#180 (comment)
I opened this in case anybody else comes across this problem.
When this bug is fixed and a new release made, this issue should be closed.