Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

webpack can not require variable ,the request of a dependency is an expression

Tags:

webpack

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"

like image 200
happy break Avatar asked Jul 29 '15 07:07

happy break


1 Answers

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.

like image 58
JuanjoFR Avatar answered Nov 20 '22 14:11

JuanjoFR