Solving Doom void-function auth-sources-user-and-password error at launch

Mar 20, 2021Blog

I use Emacs both on my laptop (a Mac) and on my desktop (a Linux). Recently, when launching emacs on my mac, I had the following error:

Error in private config: config.el, (void-function auth-source-user-and-password)

Being an emacs noob, I was a bit puzzled. From what I understood, auth-source is a default package, and this function should be available. I joined the Doom Discord server where I found help in just a few minutes.

From what I understand, Doom optimizes Emacs a lot by lazy loading packages. This is why it is so quick to launch (and a joy to use). In my config.el file, I was calling the auth-source-user-and-password directly. This was the source of the problem. When configuring packages in Doom, make sure you use hooks such as after! which will run the code once a package has loaded. In my case, it looked like that in the end:

(after! auth-source
    (setq foobar-credentials (auth-source-user-and-password "foobar"))
)

This solved the error at launch and let me use the credential in my configuration.

Tags