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

匿名 (未验证) 提交于 2019-12-03 01:23:02

问题:

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"

回答1:

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.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!