Fix async loading of modules in function node

This commit is contained in:
Nick O'Leary 2021-07-14 21:10:59 +01:00
parent cce6a47f11
commit 395b499856
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9

View File

@ -306,18 +306,19 @@ module.exports = function(RED) {
sandbox[vname] = null;
var spec = module.module;
if (spec && (spec !== "")) {
RED.import(module.module).then(lib => {
moduleLoadPromises.push(RED.import(module.module).then(lib => {
sandbox[vname] = lib;
}).catch(err => {
node.error(RED._("function.error.moduleLoadError",{module:module.spec, error:err.toString()}))
moduleErrors = true;
throw err;
});
}));
}
}
});
if (moduleErrors) {
throw new Error(RED._("function.error.externalModuleLoadError"));
}
}
Promise.all(moduleLoadPromises).then(() => {
const RESOLVING = 0;
const RESOLVED = 1;
const ERROR = 2;
@ -333,7 +334,7 @@ module.exports = function(RED) {
processMessage(msg, send, done);
}
});
Promise.all(moduleLoadPromises).then(() => {
var context = vm.createContext(sandbox);
try {
var iniScript = null;