在“mple.js”档案中,我有一张 j印功能。 情况如下:
varmapDict ={100 : test_100.js , 200 : test_200_API.js , 300 : test_300_API.js }
function mapAPI()
{
this.version = 0.1;
}
mapAPI.prototype.getFileName = function( id ) {
return mapDict[id]
}
module.exports = mapAPI;
在另一个名为“机构......js”的档案中,我想动态地要求上述“测试——xxx_API”档案。 我有以下法典:
const mapAPI = require( ../../sample.js );
const map = new mapAPI();
const mapFile = map.getFileName("100");
var insAPI = require(mapFile);
当我由“Nodeinstitut.js”指挥实施该守则时,我发现以下错误:
Error: Cannot find module ./test_100_API.js .
But the "test_100_API.js" file exists and is located in the current folder besides "institute.js". When I changed var insAPI = require(mapFile);
to var insAPI = require("./test_100_API.js");
and give it the exact path instead of dynamic path, it works fine. Can anyone help me?
提前