Skip to content

Commit 54a3f85

Browse files
authored
Fix bug where ESM module load fails on windows. (#3692)
Patch allows Windows users to deploy Firebase Functions packaged as ES module. We apply the same fix we made for Windows ES module support in the Functions Emulator (#3574) to the triggerParser script. Fixes #3689
1 parent 91f38b8 commit 54a3f85

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
- Track use of runtime config and environment variables on function deploys. (#3704)
1+
- Fixes bug where functions packaged as ES module failed to load on Windows. (#3692)
2+
- Tracks use of runtime config and environment variables on function deploys. (#3704)

src/deploy/functions/runtimes/node/triggerParser.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// from a functions package directory.
33
"use strict";
44

5+
var url = require("url");
56
var extractTriggers = require("./extractTriggers");
67
var EXIT = function () {
78
process.exit(0);
@@ -21,8 +22,10 @@ async function loadModule(packageDir) {
2122
return require(packageDir);
2223
} catch (e) {
2324
if (e.code === "ERR_REQUIRE_ESM") {
24-
const mod = await dynamicImport(require.resolve(packageDir));
25-
return mod;
25+
const modulePath = require.resolve(packageDir);
26+
// Resolve module path to file:// URL. Required for windows support.
27+
const moduleURL = url.pathToFileURL(modulePath).href;
28+
return await dynamicImport(moduleURL);
2629
}
2730
throw e;
2831
}

0 commit comments

Comments
 (0)