1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

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