CairoMakie with Julia 1.8 on VScode

I keep having this issue occasionally. Having to reinstall CairoMakie.jl and restart VScode every time this happened was quite painful, so I tried to find a simpler solution.

And the following is the simplest solution I have found so far (and may indicate the cause of the problem to someone who is more knowledgeable). First of all, I realized that when this error happened I was in the environment of the package I was developing at the moment. In other words, when I have this error during using CairoMakie, if I enter the package manager mode, the prompt is shown as

(PKG_NAME) pkg>

where PKG_NAME is the name of the package I am developing. Now, to resolve the error, go into the home environment by

(PKG_NAME) pkg> activate
  Activating project at `~/.julia/environments/v1.8`

(@v1.8) pkg>

Notice the prompt has changed to show the Julia version. Exit the package manager mode, and import CairoMakie again:

julia> using CairoMakie

This time, the error does not happen. Note that you don’t have to reinstall CairoMakie or restart VScode.

So, the error seems related to the environment issue. Hope that this additional information helps someone more knowledgeable to come up with a solution.