function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Alaric WimerAlaric Wimer 

Unable to run any CLI commands for my SFDX projects except for creating a project

I am getting an error when I run CLI commands after creating a project: Cannot read property 'getInstance' of undefined

 

I am suddenly unable to do any CLI commands with both existing and new projects. The only thing I can do is create the initial project. Everything else gives me this error.

 

Here's the error in the console:

 

console.ts:137 [Extension Host] {
"status": 1,
"name": "TypeError",
"message": "Cannot read property 'getInstance' of undefined",
"exitCode": 1,
"commandName": "ConfigGetCommand",
"stack": "TypeError: Cannot read property 'getInstance' of undefined\n at ConfigGetCommand.hooksFromLifecycleEvent (/Users/alaricwimer/.local/share/sfdx/node_modules/salesforce-alm/node_modules/@salesforce/command/lib/sfdxCommand.js:401:44)\n at ConfigGetCommand.init (/Users/alaricwimer/.local/share/sfdx/node_modules/salesforce-alm/node_modules/@salesforce/command/lib/sfdxCommand.js:248:20)\n at async ConfigGetCommand._run (/Users/alaricwimer/.local/share/sfdx/node_modules/salesforce-alm/node_modules/@salesforce/command/lib/sfdxCommand.js:92:13)\n at async Config.runCommand (/Users/alaricwimer/.local/share/sfdx/client/7.69.0-c7be45ae22/node_modules/@oclif/config/lib/config.js:172:9)\n at async Main.run (/Users/alaricwimer/.local/share/sfdx/client/7.69.0-c7be45ae22/node_modules/@oclif/command/lib/main.js:22:9)\n at async Main._run (/Users/alaricwimer/.local/share/sfdx/client/7.69.0-c7be45ae22/node_modules/@oclif/command/lib/command.js:43:20)\n at async Object.run (/Users/alaricwimer/.local/share/sfdx/client/7.69.0-c7be45ae22/dist/cli.js:32:20)\nOuter stack:\n at Function.wrap (/Users/alaricwimer/.local/share/sfdx/node_modules/salesforce-alm/node_modules/@salesforce/core/lib/sfdxError.js:151:27)\n at ConfigGetCommand.catch (/Users/alaricwimer/.local/share/sfdx/node_modules/salesforce-alm/dist/ToolbeltCommand.js:247:46)\n at async ConfigGetCommand._run (/Users/alaricwimer/.local/share/sfdx/node_modules/salesforce-alm/node_modules/@salesforce/command/lib/sfdxCommand.js:97:13)\n at async Config.runCommand (/Users/alaricwimer/.local/share/sfdx/client/7.69.0-c7be45ae22/node_modules/@oclif/config/lib/config.js:172:9)\n at async Main.run (/Users/alaricwimer/.local/share/sfdx/client/7.69.0-c7be45ae22/node_modules/@oclif/command/lib/main.js:22:9)\n at async Main._run (/Users/alaricwimer/.local/share/sfdx/client/7.69.0-c7be45ae22/node_modules/@oclif/command/lib/command.js:43:20)\n at async Object.run (/Users/alaricwimer/.local/share/sfdx/client/7.69.0-c7be45ae22/dist/cli.js:32:20)",
"warnings": []
}

 

Does anyone know how I can fix this?

Best Answer chosen by Alaric Wimer
Alain CabonAlain Cabon
Ok good.  That was a corrupt installation. When the core is touched, that was the best option indeed (reinstallation).

Your version was correct nevertheless (the most recent). You had verified it yet (previous message) that suggested a "correct" installation but it was corrupted after all.
 

All Answers

Alain CabonAlain Cabon
Hi Alaric,

1) I have the same error frequently. That could be just one new "bad" static resource (for sfdx) that you cannot retrieve anymore.

2) There are also some recent metadata types that could be still unavailable if your sfdx CLI has not been updated recently. What is you version?
   
    sfdx --version

3) Did you create a project with a manifest? You can remove the member of the static resource from the package.xml and retry.

4) You can activate this flag  --loglevel=TRACE for many sfdx commands to see more internal details (and --json for post-processing of the result).
 
Alaric WimerAlaric Wimer
Hi Alain, thank you for your reply. Here's some more information:

1. I have created two new SFDX projects, one with manifest, and one without. Both give the same error when running sfdx commands. Even simple ones like sfdx force:org:list

2. My SFDX Version = sfdx-cli/7.69.0-c7be45ae22 darwin-x64 node-v12.18.3

3. I removed Static Resources from package.xml for my project with manifest, and same error occurs.

4. when I run sfdx force:org:list --loglevel=TRACE --json, here is my output: https://prnt.sc/ty0hdi

5. When I run npm install -g sfdx-cli to update npm, I get this response: https://prnt.sc/ty0jur

It's very strange that this started happening all of a sudden. I can't think of anything I did to cause this. But now, all my projects and new projects are affected.

Any other help or guidance you have would be greatly appreciated. Thanks again.
Alain CabonAlain Cabon
According your trace, the problem occurs exactly here :

4.   const lifecycle = core_1.Lifecycle.getInstance();

core_1 is undefined or incomplete in your case (I don't know why)

You can modify: C:\Users\...\AppData\Roaming\npm\node_modules\sfdx-cli\node_modules\salesforce-alm\node_modules\@salesforce\command\lib\sfdxCommand.js
/**
     * register events for command specific hooks
     */
    async hooksFromLifecycleEvent(lifecycleEventNames) {
        lifecycleEventNames.forEach(eventName => {
              console.log('>>> eventName:' + eventName);
        });
        for (const prop in core_1) {
            if (core_1.hasOwnProperty(prop)) {    
            //   console.log(">>> " + `${prop}: ${core_1[prop]}`)
                console.log(">>> " + prop)
            }
        }
        const options = {
            Command: this.ctor,
            argv: this.argv,
            commandId: this.id
        };
        const lifecycle = core_1.Lifecycle.getInstance();
        lifecycleEventNames.forEach(eventName => {
            lifecycle.on(eventName, async (result) => {
                await this.config.runHook(eventName, Object.assign(options, { result }));
            });
        });
    }

All the SFDX commands are javascript files and we can change them for a try with new console.log commands like above.

console.log('>>> eventName:' + eventName);

console.log(">>> " + prop)

My results for core_1 :   Lifecycle is well defined here.
>>> Aliases
>>> AliasGroup
>>> AuthInfoConfig
>>> ConfigFile
>>> ConfigGroup
>>> BaseConfigStore
>>> OrgUsersConfig
>>> Config
>>> ConfigAggregator
>>> AuthInfo
>>> OAuth2WithVerifier
>>> SfdcUrl
>>> Connection
>>> SFDX_HTTP_HEADERS
>>> Mode
>>> Global
>>> Lifecycle
>>> LoggerLevel
>>> Logger
>>> Messages
>>> Org
>>> SfdxProject
>>> SfdxProjectJson
>>> SchemaPrinter
>>> SchemaValidator
>>> SfdxError
>>> SfdxErrorConfig
>>> PollingClient
>>> CometClient
>>> StreamingClient
>>> MyDomainResolver
>>> DefaultUserFields
>>> REQUIRED_FIELDS
>>> User
>>> fs
>>> sfdc

It is related to the command OrgListCommand.

What is your result of "sfdx force:org:list" ?

 
Alaric WimerAlaric Wimer
Hi Alain, I decided to just uninstall the Salesforce CLI and reinstall again by following this help documentation (https://developer.salesforce.com/docs/atlas.en-us.sfdx_setup.meta/sfdx_setup/sfdx_setup_uninstall.htm#:~:text=Select%20Start%20%3E%20Control%20Panel%20%3E%20Programs,your%20home%20directory,%20delete%20the%20.). It works again now. Still don't know what the true cause of the problem was, but this has fixed it. What a relief!
Alain CabonAlain Cabon
Ok good.  That was a corrupt installation. When the core is touched, that was the best option indeed (reinstallation).

Your version was correct nevertheless (the most recent). You had verified it yet (previous message) that suggested a "correct" installation but it was corrupted after all.
 
This was selected as the best answer