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 ES Module loading with abolute path #3070

Merged
merged 3 commits into from Jan 21, 2022
Merged
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
7 changes: 6 additions & 1 deletion src/plugin.ts
@@ -1,5 +1,6 @@
import path from "path";
import assert from "assert";
import { pathToFileURL } from "url";
import { satisfies } from "semver";
import getVersion from "./version";
import { Logger } from "./logger";
Expand Down Expand Up @@ -189,7 +190,11 @@ major incompatibility issues and thus is considered bad practice. Please inform

// try to require() it and grab the exported initialization hook
// eslint-disable-next-line @typescript-eslint/no-var-requires
const pluginModules = this.isESM ? await _importDynamic(mainPath) : require(mainPath);

// pathToFileURL(specifier).href to turn a path into a "file url"
// see https://github.com/nodejs/node/issues/31710

const pluginModules = this.isESM ? await _importDynamic(pathToFileURL(mainPath).href) : require(mainPath);

if (typeof pluginModules === "function") {
this.pluginInitializer = pluginModules;
Expand Down