diff --git a/index.js b/index.js index 5dacc8d88..98c8f8249 100644 --- a/index.js +++ b/index.js @@ -823,7 +823,11 @@ Read more on https://git.io/JJc0W`); this._checkForMissingMandatoryOptions(); // Want the entry script as the reference for command name and directory for searching for other files. - const scriptPath = this._scriptPath; + let scriptPath = this._scriptPath; + // Fallback in case not set, due to how Command created or called. + if (!scriptPath && process.mainModule) { + scriptPath = process.mainModule.filename; + } let baseDir; try {