Merge pull request #3541 from node-red/fix-import-node-library

Fix importing external module from node-red module
This commit is contained in:
Nick O'Leary 2022-04-25 20:33:25 +01:00 committed by GitHub
commit 861379c227
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 2 deletions

View File

@ -16,6 +16,7 @@
const path = require("path");
const semver = require("semver");
const url = require("url");
const {events,i18n,log} = require("@node-red/util");
var runtime;
@ -53,8 +54,8 @@ function requireModule(name) {
function importModule(name) {
var moduleInfo = require("./index").getModuleInfo(name);
if (moduleInfo && moduleInfo.path) {
var relPath = path.relative(__dirname, moduleInfo.path);
return import(relPath);
const moduleFile = url.pathToFileURL(require.resolve(moduleInfo.path));
return import(moduleFile);
} else {
// Require it here to avoid the circular dependency
return require("./externalModules").import(name);