动态通过字符串需要一个模块

Dynamic require a module by string

require('Something') //working fine
require(`${dynamicName}`) //not work with node prompt for out of memory

能否就如何根据变量动态要求模块提出建议 'dynamicName'?

您始终可以用自己的版本覆盖 require,因为它是一个函数。

function setupMyRequire() {
    var tmpreq = global.require;
    global.require = function(name) {
        // parse name here
        console.log('will require', name);
        tmpreq(name);
    };
}