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

Use file:// url with dynamic import

This commit is contained in:
Nick O'Leary 2021-07-21 11:00:24 +01:00
parent 233a1995b3
commit a8d093bacd
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9

View File

@ -10,6 +10,7 @@ const clone = require("clone");
const exec = require("@node-red/util").exec;
const log = require("@node-red/util").log;
const hooks = require("@node-red/util").hooks;
const url = require("url");
const BUILTIN_MODULES = require('module').builtinModules;
@ -139,7 +140,8 @@ function importModule(module) {
const externalModuleDir = getInstallDir();
const moduleDir = path.join(externalModuleDir,"node_modules",module);
// Import needs the full path to the module's main .js file
const moduleFile = require.resolve(moduleDir);
// It also needs to be a file:// url for Windows
const moduleFile = url.pathToFileURL(require.resolve(moduleDir));
return import(moduleFile);
}