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

Support using nconf in a (browserify-based) browser context #130

Closed
ronjouch opened this issue Dec 4, 2014 · 13 comments · Fixed by #252
Closed

Support using nconf in a (browserify-based) browser context #130

ronjouch opened this issue Dec 4, 2014 · 13 comments · Fixed by #252

Comments

@ronjouch
Copy link

ronjouch commented Dec 4, 2014

Hi.

Like StackOverflow post "using nconf in the browser", I'm trying to use your package in a browserify setup, but because nconf calls fs.readdirSync when it is require()d to scan directories for configuration, it fails in the browser.

→ Is it something that sounds feasible with nconf, or do you suggest going for another package / custom solution?

Thanks for the help, and sorry for posting this as an issue, it's more of a question to which "we do not and will not support that" can be a fine answer.

@toddpi314
Copy link

+1

@toddpi314
Copy link

This module has some potential, but it doesn't work on the current source of NConf because of the 'lazy-loading' of the files: https://github.com/substack/brfs

@naoufal
Copy link

naoufal commented Jan 6, 2015

+1

@ronjouch
Copy link
Author

ronjouch commented Jan 6, 2015

OP here. @toddpi314 @naoufal, I ended up using mozilla's convict module, which I bent to my browser needs through a little intermediate layer using superagent. See discussion in mozilla/node-convict#47 , which lead to a solution now documented in their README.md and probably applicable to nconf too:

  • Ignore the system and file modules (in Gulp, add .ignore('system').ignore('file') to your browserify pipe).
  • Use brfs to ensure the fs.loadFileSync schema-loading calls are inlined at build time rather than resolved at runtime (in Gulp, add .transform(brfs) to your browserify pipe).
  • To support "loading configuration from a http://foo.bar/some.json URL", build a thin wrapper around convict using your favorite http package (e.g. superagent). Typically, in the success callback, call convict's load() on the body of the response.

@indexzero @jcrugzz if you deem this solution applicable and acceptable in nconf, feel free to close.

@naoufal
Copy link

naoufal commented Jan 6, 2015

Thanks @ronjouch. I'll give that a shot and report back.

@indexzero
Copy link
Owner

Not sure I follow: is it lazy-loading or lazy-loading the directory? In other words, does d501e7b fix it?

@tragiclifestories
Copy link

@indexzero It fixed it for me, FWIW. I'm using browserify.

@mrfelton
Copy link

When I use d501e7b I get a different error

Error: Cannot find module './nconf/stores/env'

@particle4dev
Copy link

Hi,
I still get this error in v0.7.1. Have you guys fixed it ?
Uncaught TypeError: fs.readdirSync is not a function
cc @indexzero

@generalpiston
Copy link

d501e7b fixes things for me as well. Using webpack.

@fikriauliya
Copy link

As mentioned above, d501e7b fixes the issue by removing the usage of fs. However, the current code uses fs again

@syarul
Copy link

syarul commented Aug 23, 2016

Still getting error after compiling with browserify

return new (require('../nconf')[common.capitalize(type.toLowerCase())])(opti

TypeError: object is not a function

@1R053
Copy link
Contributor

1R053 commented Jan 29, 2017

also webpack builds for a nodejs context fails with "Error: ENOENT: no such file or directory, scandir '//nconf/stores'" due to the lazy loading pattern based on fs.

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