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

require doesn't work when path is a variable #664

Closed
ghost opened this issue Feb 20, 2014 · 4 comments
Closed

require doesn't work when path is a variable #664

ghost opened this issue Feb 20, 2014 · 4 comments

Comments

@ghost
Copy link

ghost commented Feb 20, 2014

I am trying to do something like this

// config.js
var path = require("path"),
    env = process.env.NODE_ENV || "fail";

module.exports = require(path.join(__dirname, env));

Some file that uses the config

// app.js
var config = require("./config");
console.log(config);

And bundle with this command

NODE_ENV=test browserify -d app.js > public/test/app.js

Browserify is not picking up the NODE_ENV assignment and it's trying to include fail environment when I run my testing bundle 😦

Uncaught Error: Cannot find module '/config/fail' 
@ghost
Copy link

ghost commented Feb 20, 2014

browserify doesn't work with conditional requires and can't be made to work with arbitrary dynamic requires without solving the halting problem first. Do something different instead. This is a dead end.

@ghost ghost closed this as completed Feb 20, 2014
@ghost
Copy link
Author

ghost commented Feb 20, 2014

😳 a response from the master!

Thank you for such a pragmatic response. I'll do a little more research and see what other things I can do to solve the problem.

@thlorenz
Copy link
Collaborator

@naomik have a look at the browser-field to load different modules in the browser than in node.

If you need more power, i.e. swap out modules for different environments browserify-swap may help you, but you gotta have a real good reason to do that (kinda hacky).

@jhnns
Copy link
Contributor

jhnns commented Feb 22, 2014

Usually dynamic dependencies are not necessary 😄

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

No branches or pull requests

2 participants