zowe / zowe-cli

Zowe CLI
Eclipse Public License 2.0
116 stars 86 forks source link

ESM and REPL environments hit exception in `DefaultCredentialManager.initialize` #2299

Closed traeok closed 1 month ago

traeok commented 1 month ago

Cause

require.main is undefined in the Node.js REPL and in ESM environments, causing an unhandled TypeError to occur before Imperative can finish initializing the default credential manager.


Discussed in https://github.com/zowe/zowe-cli/discussions/2295:

Originally posted by **kumnar02** October 7, 2024 using below code m i'm getting Failed to initialize secure credential manager , any idea whats wrong ? ```typescript import { ProfileInfo } from "@zowe/imperative"; import { GetJobs } from "@zowe/zos-jobs-for-zowe-sdk"; (async () => { // Load connection info from default z/OSMF profile const profInfo = new ProfileInfo("zowe"); await profInfo.readProfilesFromDisk(); const zosmfProfAttrs = profInfo.getDefaultProfile("zosmf"); const zosmfMergedArgs = profInfo.mergeArgsForProfile(zosmfProfAttrs, { getSecureVals: true }); const session = ProfileInfo.createSession(zosmfMergedArgs.knownArgs); const owner: string = session.ISession.user; // This may take awhile... const response = await GetJobs.getJobsByOwner(session, owner); console.log(response); })().catch((err) => { console.error(err); process.exit(1); }); ```
github-actions[bot] commented 1 month ago

Thank you for creating a bug report. We will investigate the bug and evaluate its impact on the product. If you haven't already, please ensure you have provided steps to reproduce the bug and as much context as possible.