Skip to content

Commit

Permalink
Fix bug where ESM module load fails on windows. (firebase#3692)
Browse files Browse the repository at this point in the history
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 (firebase#3574) to the triggerParser script.

Fixes firebase#3689
  • Loading branch information
taeold authored and devpeerapong committed Dec 14, 2021
1 parent a694668 commit 7710fd5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
- Track use of runtime config and environment variables on function deploys. (#3704)
- Fixes bug where functions packaged as ES module failed to load on Windows. (#3692)
- Tracks use of runtime config and environment variables on function deploys. (#3704)
7 changes: 5 additions & 2 deletions src/deploy/functions/runtimes/node/triggerParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// from a functions package directory.
"use strict";

var url = require("url");
var extractTriggers = require("./extractTriggers");
var EXIT = function () {
process.exit(0);
Expand All @@ -21,8 +22,10 @@ async function loadModule(packageDir) {
return require(packageDir);
} catch (e) {
if (e.code === "ERR_REQUIRE_ESM") {
const mod = await dynamicImport(require.resolve(packageDir));
return mod;
const modulePath = require.resolve(packageDir);
// Resolve module path to file:// URL. Required for windows support.
const moduleURL = url.pathToFileURL(modulePath).href;
return await dynamicImport(moduleURL);
}
throw e;
}
Expand Down

0 comments on commit 7710fd5

Please sign in to comment.