You need to do:
using CairoMakie
f = Figure()
ax = Axis(f[1,1], spinewidth = 1, xgridvisible = false, ygridvisible = false, xtickwidth = 1)
hidespines!(ax,:t,:r)
lineobject = lines!(ax, 0..10, sin, color = :red)
ax.xtrimspine=true
ax.ytrimspine=true
f
Since otherwise, without anything plotted, the ticks are empty and trimspine will try to access the ticks
