Atom.config.get() does not return default value


I’m trying to read a value from config once my package is activated. Here are my settings:

    title: 'Terminal Emulator'
    description: 'The package supports
    type: 'string'
    enum: ['', '']
    default: ''

According to the Atom API guide, atom.config.get() should return the default value for a setting, if the user hasn’t specified settings. Indeed, when I don’t change anything in the settings view, my config.cson shows no configuration for my package:

"repl-term": {}

Once I make a change in the settings view (i.e. change from the default value to the alternative), that change is reflected in config.cson:

  terminalEmulator: ""

However, when calling atom.config.get() with no changes to the setting (i.e. terminalEmulator is ""), it returns 'undefined'. Here’s the code where I try get the value of my config parameter:

Terminal: atom.config.get('repl-term.terminalEmulator')

This happens inside a module I load from my main file.

Any ideas what I’m missing? I’ve found references to setDefaults(), which seems to no longer be part of the API.



Your code looks right to me. Just to be sure if it’s a bug with Atom, does it also happen when you run Atom in safe mode (atom --safe from the command line)?

In the meantime, you can use

Terminal: atom.config.get('repl-term.terminalEmulator') ? @config.terminalEmulator.default

to get the default value if atom.config.get returns undefined undefined.

1 Like

Just as an aside, the title field in your configuration isn’t necessary. The humanizing algorithm will convert terminalEmulator to Terminal Emulator for you before displaying it to the user. Also, please see the Note in the documentation:

Note: You should strive to be so clear in your naming of the setting that you do not need to specify a title or description!

1 Like

Thanks. How do I load my package when in safe mode? Looks to me like non-core packages are loaded…

Using your temporary fix

module.exports =
  Terminal: atom.config.get('repl-term.terminalEmulator') ?

I get the error Cannot read property 'terminalEmulator' of undefined.

I think a problem is that I’m accessing the config from within a module called This module is loaded outside the module.export in my main coffeescript file. Inside the module export of my main file I define and set the config. How do I need to rearrange this?

I guess, I should put the terminal handler inside a class and create a terminal handler instance after setting the config?

Oh right, I did not think about packages not loading in safe mode. You can open the dev tools (ctrl+shift+i) and in the console tab run atom.packages.activatePackage('/path/to/package') to activate the package.

You can just require that settings file from the other file:

settings = require './settings'

  Terminal: atom.config.get(...) ? settings.terminalEmulator.default

I’ve loaded my package in safe mode, I’m facing the same issue there. I believe the root of the problem is that I’m trying to access settings inside a module before the main module has exported the settings. Does that make sense? Or should am I wrong and it should work nevertheless, because the settings only need to be present at runtime (of a function like launchRepl)?

Your workaround works like a charm now.

Ah… I think you’re right, I understand what’s happening now. You should move the terminalHandler = require './terminal-handler' into your activate function, because indeed it is trying to get a config value even before your package is activated.


Yeah that works. Cool.

I think I’m facing the same issue. I have a setting with a default that needs to be used on startup of the package. Currently I get undefined even though I have a default.

module.exports = Ensime =
  subscriptions: null

  config: {
    ensimeServerVersion: {
      description: 'Version of Ensime server',
      type: 'string',
      default: "0.9.10-SNAPSHOT"

And then:


gives undefined if run during activation which is really what I need. I this not supported?

This is the first package with a capital letter in the package name that I’ve seen, maybe that’s it? What if you try atom.config.get('ensime.ensimeServerVersion')?

Oh, turns out my issue was only myself. It actually did work and the undefined came from later misuse. Thanks!

1 Like

Good to know it’s nothing to do with capital letters and nice you figured it out :smile:

1 Like

Sorry to necrobump but this was the only thread I could find about this issue, and it’s better to consolidate information into one place.

I was suffering from this issue myself before I discovered that it was due to capital letters in my package name.

ie: if I put in package.json:
“name”: “Atomtech”
or similar, then config will fail to load defaults, and fail to load settings at all in that regards, even if I tried to config.get(“”)

1 Like