Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'Env' Store is Loaded Twice #363

Open
sploicers opened this issue Apr 21, 2021 · 3 comments
Open

'Env' Store is Loaded Twice #363

sploicers opened this issue Apr 21, 2021 · 3 comments

Comments

@sploicers
Copy link

sploicers commented Apr 21, 2021

Exactly as the title says - when I configure Nconf with the code below I can verify that Provider.prototype.add is called with the 'name' argument set to 'env' two times. This results in some of my environment variables getting clobbered and not ending up in the finally built store.

The following breakpoint (placed in provider.js of the Nconf source code) is what I used to demonstrate this:
image

The configuration that I'm using to reproduce this is:

nconf
.overrides(overrides)
.argv()
.env({
	separator: '__',
	parseValues: true,
	transform: transformer
})
.file(configFile)
.defaults(configDefaults);

I have verified that the block of code above is only hit once.

npm list nconf tells me I am on version 0.10.0.

@mhamann
Copy link
Collaborator

mhamann commented Apr 21, 2021

Thanks for reporting this @sploicers. Are you seeing it called twice in sequence or interspersed between calls from other stores?

Can you also describe in more detail about your setup and what you're providing at each stage of the hierarchy?

@sploicers
Copy link
Author

sploicers commented Apr 22, 2021

Hi, no worries 😄

I'm seeing it interspersed between calls from other stores. This is code from work (which is already partially obfuscated for this post) so can't post too much more detail about it, except that overrides and configDefaults are just a plain old objects, configFile is JSON, and the transformer function tries to strip off a certain prefix and returns false if it's not found. This is because we only want envars having that prefix to be in the store - interestingly this is true the first time that Env.loadSync() is called, but the second time it seems to include every envar that's set.

Setup-wise it's a Node/Express service running on Node 12, under Mac OS Catalina 10.15.7.

As an update, I've just seen that the second time Provider.prototype.add is called with a name argument of 'env', the options object is undefined. The first time it is called it receives the options that I specify in the setup code.

@mhamann
Copy link
Collaborator

mhamann commented Jun 9, 2021

I potentially just ran into this same issue on a project I was working on last week. I'm not sure what would cause it off-hand, but it definitely needs further investigation. Hoping I can get time to do that soon, but would welcome anyone else doing some digging and submitting a PR with a fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants