how to require a variable. i can work like this
var config={
example1 : require("example1/main.js"),
example2 : require("example2/main.js")
}
when I use like
var modules=["example1","example2"]
_.each(modules,function(module){
require(module+"/main.js")
})
this error is "Cannot find module 'example1/main.js"
I had a similar problem and solved it by specifying the full path, e.g., in your case:
var modules=["example1","example2"];
_.each(modules,function(module){
require("./"+module+"/main.js");
});
Maybe this example can help you.
This type of error is related to the context.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With