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

Config just keeps finding ITS OWN base directory inside node_modules #330

Closed
deni-zen opened this issue Jun 16, 2016 · 4 comments
Closed

Comments

@deni-zen
Copy link

deni-zen commented Jun 16, 2016

I just installed config and started playing around with it. I have a directory structure like this:

/app
/node_modules
    /config <-- your module
 /resources
    /assets
        /js
            /myJsApp
                /config 
                    default.js <-- my config file
 package.json
 webpack.config.js

Now I've tried every which way of setting this:

NODE_CONFIG_DIR=./resources/assets/js/myJsApp/config but no matter what I do, whenever I run webpack, it just finds your config directory and craps out a bunch of errors. Where am I going wrong here?

@lorenwest
Copy link
Collaborator

lorenwest commented Jun 16, 2016

When running an app that uses node-config, you have to be very aware of the current working directory.

The only way the config package will incorrectly use /node_modules/config is if the current working directory is /node_modules, OR if $NODE_CONFIG_DIR is explicitly pointing to it.

I've found that if you're unsure of your current working directory, using a relative path for $NODE_CONFIG_DIR doesn't help much. Try using a direct path for NODE_CONFIG_DIR, or try printing out process.cwd() before loading config so you know where it's running from.

As far as using config with webpack, I don't have any experience with it, so others may want to chime in if webpack changes directories while running, etc.

@deni-zen
Copy link
Author

It's possible... check that... it's likely that I'm misuderstanding the errors I'm getting. I got the following errors when I ran webpack and assumed the library was trying to load itself as a config file...

ERROR in ./~/config/lib/config.js
Module not found: Error: Cannot resolve module 'hjson' in /Users/luke/Sites/denizen-garden/node_modules/config/lib
 @ ./~/config/lib/config.js 992:14-30

ERROR in ./~/config/lib/config.js
Module not found: Error: Cannot resolve module 'toml' in /Users/luke/Sites/denizen-garden/node_modules/config/lib
 @ ./~/config/lib/config.js 1000:13-28

ERROR in ./~/config/lib/config.js
Module not found: Error: Cannot resolve module 'cson' in /Users/luke/Sites/denizen-garden/node_modules/config/lib
 @ ./~/config/lib/config.js 1007:13-28

ERROR in ./~/config/lib/config.js
Module not found: Error: Cannot resolve module 'properties' in /Users/luke/Sites/denizen-garden/node_modules/config/lib
 @ ./~/config/lib/config.js 1018:16-37

ERROR in ./~/config/lib/config.js
Module not found: Error: Cannot resolve module 'x2js' in /Users/luke/Sites/denizen-garden/node_modules/config/lib
 @ ./~/config/lib/config.js 1024:12-27

ERROR in ./~/coffee-script/lib/coffee-script/coffee-script.js
Module not found: Error: Cannot resolve module 'module' in /Users/luke/Sites/denizen-garden/node_modules/coffee-script/lib/coffee-script
 @ ./~/coffee-script/lib/coffee-script/coffee-script.js 129:23-40 169:17-34

ERROR in ./~/coffee-script/lib/coffee-script/register.js
Module not found: Error: Cannot resolve module 'child_process' in /Users/luke/Sites/denizen-garden/node_modules/coffee-script/lib/coffee-script
 @ ./~/coffee-script/lib/coffee-script/register.js 7:18-42

ERROR in ./~/coffee-script/lib/coffee-script/register.js
Module not found: Error: Cannot resolve module 'module' in /Users/luke/Sites/denizen-garden/node_modules/coffee-script/lib/coffee-script
 @ ./~/coffee-script/lib/coffee-script/register.js 25:13-30

ERROR in ./~/coffee-script/lib/coffee-script/command.js
Module not found: Error: Cannot resolve module 'child_process' in /Users/luke/Sites/denizen-garden/node_modules/coffee-script/lib/coffee-script
 @ ./~/coffee-script/lib/coffee-script/command.js 16:8-32

ERROR in ./~/coffee-script/lib/coffee-script/repl.js
Module not found: Error: Cannot resolve module 'repl' in /Users/luke/Sites/denizen-garden/node_modules/coffee-script/lib/coffee-script
 @ ./~/coffee-script/lib/coffee-script/repl.js 11:13-28

ERROR in ./~/coffee-script/lib/coffee-script/grammar.js
Module not found: Error: Cannot resolve module 'jison' in /Users/luke/Sites/denizen-garden/node_modules/coffee-script/lib/coffee-script
 @ ./~/coffee-script/lib/coffee-script/grammar.js 5:11-27

ERROR in ./~/coffee-script/bin/coffee
Module parse failed: /Users/luke/Sites/denizen-garden/node_modules/coffee-script/bin/coffee Unexpected character '#' (1:0)
You may need an appropriate loader to handle this file type.
SyntaxError: Unexpected character '#' (1:0)
    at Parser.pp.raise (/Users/luke/Sites/denizen-garden/node_modules/webpack/node_modules/acorn/dist/acorn.js:920:13)
    at Parser.pp.getTokenFromCode (/Users/luke/Sites/denizen-garden/node_modules/webpack/node_modules/acorn/dist/acorn.js:2813:8)
    at Parser.pp.readToken (/Users/luke/Sites/denizen-garden/node_modules/webpack/node_modules/acorn/dist/acorn.js:2508:15)
    at Parser.pp.nextToken (/Users/luke/Sites/denizen-garden/node_modules/webpack/node_modules/acorn/dist/acorn.js:2500:71)
    at Parser.parse (/Users/luke/Sites/denizen-garden/node_modules/webpack/node_modules/acorn/dist/acorn.js:1615:10)
    at Object.parse (/Users/luke/Sites/denizen-garden/node_modules/webpack/node_modules/acorn/dist/acorn.js:882:44)
    at Parser.parse (/Users/luke/Sites/denizen-garden/node_modules/webpack/lib/Parser.js:902:15)
    at DependenciesBlock.<anonymous> (/Users/luke/Sites/denizen-garden/node_modules/webpack/lib/NormalModule.js:104:16)
    at DependenciesBlock.onModuleBuild (/Users/luke/Sites/denizen-garden/node_modules/webpack-core/lib/NormalModuleMixin.js:310:10)
    at nextLoader (/Users/luke/Sites/denizen-garden/node_modules/webpack-core/lib/NormalModuleMixin.js:275:25)
    at /Users/luke/Sites/denizen-garden/node_modules/webpack-core/lib/NormalModuleMixin.js:259:5
    at Storage.finished (/Users/luke/Sites/denizen-garden/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:38:16)
    at /Users/luke/Sites/denizen-garden/node_modules/graceful-fs/graceful-fs.js:78:16
    at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:404:3)
 @ ./~/coffee-script/lib/coffee-script/register.js 52:13-48

My config file is just a plain javascript file and it looks like this:

module.exports = {
    smartystreets: {
        endpoint: '//autocomplete-api.smartystreets.com/suggest',
        authId: 'xxx',
        authToken: 'xxx',
        jsonpParam: 'callback',
        key: 'xxx',
    },
    amazon: {
        region: 'us-east-1',
        IdentityPoolId: 'xxx',
        appId: 'xxx'
    }
}

@markstos
Copy link
Collaborator

Closing, as this does not appear to be a bug in node-config. If it is believed to be a bug in node-config, please provide a PR which adds a failing test to our test suite which demonstrates it.

@blahah
Copy link

blahah commented Nov 11, 2016

@deni-zen this is the same bug as #345, fixed in #358

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

No branches or pull requests

4 participants