Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug where ESM module load fails on windows. #3692

Merged
merged 4 commits into from
Aug 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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