Deferred values can't be referenced by sub-modules

I'm submitting a ...

  • [ x ] bug report
  • [ ] feature request
  • [ ] support request or question => Please do not submit support request or questions here, see note at the top of this template.

What is the current behavior?

Sub-modules that use node-config are not able to reference deferred values from the parent module.

For example, say you have a parent module with node-config installed and two config files, default and production.

default.js

const defer = require('config/defer').deferConfig;

module.exports = {
  firstName : 'default first name',
  lastName: 'default last name',
  fullName : defer(function ()  {
    return this.firstName+' '+this.lastName;
  })
} 

production.js

module.exports = {
    firstName : "Jane",
    lastName: "Doe",
 }

index.js

const config = require('config');
console.log('from parent: ' + config.fullName);

This correctly prints the full name, Jane Doe.

However, say I also have a sub-module with the following index file

child - index.js

const config = require('config');
console.log(config);
console.log('from sub-module: ' + config.fullName);

Then I update the parent module index file to the following to require the child module.
parent - index.js

const config = require('config');
console.log('from parent: ' + config.fullName);

const configDeferTestChild = require('config-defer-test-child');

The output is then:

from parent: Jane Doe
Config {
  firstName: 'Jane',
  lastName: 'Doe',
  fullName: DeferredConfig {
    prepare: [Function (anonymous)],
    resolve: [Function (anonymous)]
  }
}
from sub-module: [object Object]

Which you can see that the config values correctly resolve the values in the parent module. But in the sub-module it does not resolve.

What is the expected behavior?

Based on the wiki, I would expect that config-defer should work with sub modules as well and I should see "Jane Doe" in the sub module index file (I haven't read anything that stated otherwise).

Please tell us about your environment:

  • node-config version: 3.3.7
  • node-version: 18.0.0

Other information