Cli: RequiresProjectError: Running Certain SFDX Commands in VSCode and Command Prompt/PowerShell Yields Different Results

Created on 3 Feb 2020  Â·  5Comments  Â·  Source: forcedotcom/cli

Summary

I am able, from within vscode, to execute sfdx force:source:deploy --manifest (…) --json --loglevel fatal command for any manifest location in a project folder from the vscode terminal.
However, I cannot do the same in either Command Prompt or PowerShell, not using vscode.

Steps To Reproduce:

  1. From within vscode with Ctrl+Shift+P run the command SFDX: Create Project with Manifest
  2. Select standard template
  3. Set Project Name
  4. Select folder for project
  5. From within vscode with Ctrl+Shift+P run the command SFDX: Authorize an Org
  6. Select Project default (login.salesforce.com)
  7. Set alias
  8. Browser opens, type in credentials and log ind
  9. In vscode go to Terminal
  10. Type in sfdx force:source:deploy --manifest --json --loglevel fatal
  11. Successfully deploy (status: 0, result: deployedSource[])
  12. Copy folder from step 4 with all content to a new location
  13. Type in sfdx force:source:deploy --manifest --json --loglevel fatal
  14. Successfully deploy (status: 0, result: deployedSource[])
  15. Hit windows key and open Command Prompt
  16. Type sfdx –version to verify that sfdx command can be run outside of vscode
  17. Get response: sfdx-cli/7.43.1-ef237e8b37 win32-x64 node-v10.15.3
  18. Type in sfdx force:source:deploy --manifest --json --loglevel fatal
  19. Get error (See actual result)
  20. Repeat for new location in Step 12
  21. Get error (See actual result)
  22. Repeat above steps 15-20, just for PowerShell
  23. Get error (See actual result)

Expected result

Since I am able to run sfdx commands outside of vscode, and I have copied the files in the project folder 1:1 to a new location (thus cloning the SFDX project), I expect to be able to deploy and thus get the below result (empty deployedSource, since local repository is identical to org).
{
"status": 0,
"result": {
"deployedSource": []
}
}

Actual result

Both command prompt, powershell throw the same error. The error is not possible for me to decipher, beyond that the context of being within an SFDX project is missing:
Note, the below stack trace should include double backslashes for the folder structure.
{
"status": 1,
"name": "RequiresProjectError",
"message": "This command is required to run from within an SFDX project.",
"exitCode": 1,
"commandName": "SourceDeployCommand",
"stack": "RequiresProjectError: This command is required to run from within an SFDX project.\n at Function.create (C:\Users\userName\AppData\Local\sfdx\client\7.43.1-ef237e8b37\node_modules\@salesforce\core\lib\sfdxError.js:141:16)\n at SourceDeployCommand.assignProject (C:\Users\userName\AppData\Local\sfdx\client\7.43.1-ef237e8b37\node_modules\@salesforce\command\lib\sfdxCommand.js:110:40)",
"warnings": []
}

Additional information

vscode vs command prompt

SFDX CLI Version (to find the version of the CLI engine run sfdx --version):
sfdx-cli/7.43.1-ef237e8b37 win32-x64 node-v10.15.3

SFDX plugin Version (to find the version of the CLI plugin run sfdx plugins --core):
@oclif/plugin-autocomplete 0.1.5 (core)
@oclif/plugin-commands 1.2.3 (core)
@oclif/plugin-help 2.2.3 (core)
@oclif/plugin-not-found 1.2.3 (core)
@oclif/plugin-plugins 1.7.9 (core)
@oclif/plugin-update 1.3.9 (core)
@oclif/plugin-warn-if-update-available 1.7.0 (core)
@oclif/plugin-which 1.0.3 (core)
@salesforce/sfdx-trust 3.0.7 (core)
analytics 1.4.1 (core)
generator 1.1.2 (core)
salesforcedx 47.16.0 (core)
├─ salesforcedx-templates 47.17.0 (core)
└─ salesforce-alm 47.15.0 (core)

sfdx-cli 7.43.1 (core)

OS and version:
Windows 10, 64-bit, version 1903

Most helpful comment

That errors comes when you run a command that requires a project but your
current working directory is not a project, or more specific, doesn’t have
an sfdx-project.json file in it.

VS Code will automatically place the shell prompt into the current
workspace directory but your fresh prompt must be moved (cd ...) into that
same directory.

If you look at your file path in your promp you can see that one appears to
run from a project directory while the other is running at the root of your
user’s profile folder.

On Mon, Feb 3, 2020 at 2:44 PM Nicky Torstensson notifications@github.com
wrote:

Summary

I am able, from within vscode, to execute sfdx force:source:deploy
--manifest (…) --json --loglevel fatal command for any manifest location in
a project folder from the vscode terminal.
However, I cannot do the same in either Command Prompt or PowerShell, not
using vscode.
Steps To Reproduce:

  1. From within vscode with Ctrl+Shift+P run the command SFDX: Create
    Project with Manifest
  2. Select standard template
  3. Set Project Name
  4. Select folder for project
  5. From within vscode with Ctrl+Shift+P run the command SFDX:
    Authorize an Org
  6. Select Project default (login.salesforce.com)
  7. Set alias
  8. Browser opens, type in credentials and log ind
  9. In vscode go to Terminal
  10. Type in sfdx force:source:deploy --manifest --json --loglevel fatal
  11. Successfully deploy (status: 0, result: deployedSource[])
  12. Copy folder from step 4 with all content to a new location
  13. Type in sfdx force:source:deploy --manifest package.xml for step 12> --json --loglevel fatal
  14. Successfully deploy (status: 0, result: deployedSource[])
  15. Hit windows key and open Command Prompt
  16. Type sfdx –version to verify that sfdx command can be run outside
    of vscode
  17. Get response: sfdx-cli/7.43.1-ef237e8b37 win32-x64 node-v10.15.3
  18. Type in sfdx force:source:deploy --manifest --json --loglevel fatal
  19. Get error (See actual result)
  20. Repeat for new location in Step 12
  21. Get error (See actual result)
  22. Repeat above steps 15-20, just for PowerShell
  23. Get error (See actual result)

Expected result

Since I am able to run sfdx commands outside of vscode, and I have copied
the files in the project folder 1:1 to a new location (thus cloning the
SFDX project), I expect to be able to deploy and thus get the below result
(empty deployedSource, since local repository is identical to org).
{
"status": 0,
"result": {
"deployedSource": []
}
}
Actual result

Both command prompt, powershell throw the same error. The error is not
possible for me to decipher, beyond that the context of being within an
SFDX project is missing:
{
"status": 1,
"name": "RequiresProjectError",
"message": "This command is required to run from within an SFDX project.",
"exitCode": 1,
"commandName": "SourceDeployCommand",
"stack": "RequiresProjectError: This command is required to run from
within an SFDX project.n at Function.create
(C:Users\AppDataLocalsfdxclient7.43.1-ef237e8b37node_modules
@salesforce https://github.com/salesforcecorelibsfdxError.js:141:16)n
at SourceDeployCommand.assignProject
(C:Users\AppDataLocalsfdxclient7.43.1-ef237e8b37node_modules
@salesforce https://github.com/salesforce
commandlibsfdxCommand.js:110:40)",
"warnings": []
}
Additional information

[image: vscode vs command prompt]
https://user-images.githubusercontent.com/55800560/73693311-430b9680-46d6-11ea-841f-05a462b9494c.png

SFDX CLI Version(to find the version of the CLI engine run sfdx
--version):
sfdx-cli/7.43.1-ef237e8b37 win32-x64 node-v10.15.3

SFDX plugin Version(to find the version of the CLI plugin run sfdx
plugins --core):
@oclif/plugin-autocomplete 0.1.5 (core)
@oclif/plugin-commands 1.2.3 (core)
@oclif/plugin-help 2.2.3 (core)
@oclif/plugin-not-found 1.2.3 (core)
@oclif/plugin-plugins 1.7.9 (core)
@oclif/plugin-update 1.3.9 (core)
@oclif/plugin-warn-if-update-available 1.7.0 (core)
@oclif/plugin-which 1.0.3 (core)
@salesforce/sfdx-trust 3.0.7 (core)
analytics 1.4.1 (core)
generator 1.1.2 (core)
salesforcedx 47.16.0 (core)
├─ salesforcedx-templates 47.17.0 (core)
└─ salesforce-alm 47.15.0 (core)

sfdx-cli 7.43.1 (core)

OS and version:
Windows 10, 64-bit, version 1903

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/forcedotcom/cli/issues/294?email_source=notifications&email_token=AAQSRPFVIIUD3XO7UICBZATRBCF5LA5CNFSM4KPMSSL2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4IKXBV4A,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AAQSRPF5XQ4BTBBHDUBMLXDRBCF5LANCNFSM4KPMSSLQ
.

All 5 comments

That errors comes when you run a command that requires a project but your
current working directory is not a project, or more specific, doesn’t have
an sfdx-project.json file in it.

VS Code will automatically place the shell prompt into the current
workspace directory but your fresh prompt must be moved (cd ...) into that
same directory.

If you look at your file path in your promp you can see that one appears to
run from a project directory while the other is running at the root of your
user’s profile folder.

On Mon, Feb 3, 2020 at 2:44 PM Nicky Torstensson notifications@github.com
wrote:

Summary

I am able, from within vscode, to execute sfdx force:source:deploy
--manifest (…) --json --loglevel fatal command for any manifest location in
a project folder from the vscode terminal.
However, I cannot do the same in either Command Prompt or PowerShell, not
using vscode.
Steps To Reproduce:

  1. From within vscode with Ctrl+Shift+P run the command SFDX: Create
    Project with Manifest
  2. Select standard template
  3. Set Project Name
  4. Select folder for project
  5. From within vscode with Ctrl+Shift+P run the command SFDX:
    Authorize an Org
  6. Select Project default (login.salesforce.com)
  7. Set alias
  8. Browser opens, type in credentials and log ind
  9. In vscode go to Terminal
  10. Type in sfdx force:source:deploy --manifest --json --loglevel fatal
  11. Successfully deploy (status: 0, result: deployedSource[])
  12. Copy folder from step 4 with all content to a new location
  13. Type in sfdx force:source:deploy --manifest package.xml for step 12> --json --loglevel fatal
  14. Successfully deploy (status: 0, result: deployedSource[])
  15. Hit windows key and open Command Prompt
  16. Type sfdx –version to verify that sfdx command can be run outside
    of vscode
  17. Get response: sfdx-cli/7.43.1-ef237e8b37 win32-x64 node-v10.15.3
  18. Type in sfdx force:source:deploy --manifest --json --loglevel fatal
  19. Get error (See actual result)
  20. Repeat for new location in Step 12
  21. Get error (See actual result)
  22. Repeat above steps 15-20, just for PowerShell
  23. Get error (See actual result)

Expected result

Since I am able to run sfdx commands outside of vscode, and I have copied
the files in the project folder 1:1 to a new location (thus cloning the
SFDX project), I expect to be able to deploy and thus get the below result
(empty deployedSource, since local repository is identical to org).
{
"status": 0,
"result": {
"deployedSource": []
}
}
Actual result

Both command prompt, powershell throw the same error. The error is not
possible for me to decipher, beyond that the context of being within an
SFDX project is missing:
{
"status": 1,
"name": "RequiresProjectError",
"message": "This command is required to run from within an SFDX project.",
"exitCode": 1,
"commandName": "SourceDeployCommand",
"stack": "RequiresProjectError: This command is required to run from
within an SFDX project.n at Function.create
(C:Users\AppDataLocalsfdxclient7.43.1-ef237e8b37node_modules
@salesforce https://github.com/salesforcecorelibsfdxError.js:141:16)n
at SourceDeployCommand.assignProject
(C:Users\AppDataLocalsfdxclient7.43.1-ef237e8b37node_modules
@salesforce https://github.com/salesforce
commandlibsfdxCommand.js:110:40)",
"warnings": []
}
Additional information

[image: vscode vs command prompt]
https://user-images.githubusercontent.com/55800560/73693311-430b9680-46d6-11ea-841f-05a462b9494c.png

SFDX CLI Version(to find the version of the CLI engine run sfdx
--version):
sfdx-cli/7.43.1-ef237e8b37 win32-x64 node-v10.15.3

SFDX plugin Version(to find the version of the CLI plugin run sfdx
plugins --core):
@oclif/plugin-autocomplete 0.1.5 (core)
@oclif/plugin-commands 1.2.3 (core)
@oclif/plugin-help 2.2.3 (core)
@oclif/plugin-not-found 1.2.3 (core)
@oclif/plugin-plugins 1.7.9 (core)
@oclif/plugin-update 1.3.9 (core)
@oclif/plugin-warn-if-update-available 1.7.0 (core)
@oclif/plugin-which 1.0.3 (core)
@salesforce/sfdx-trust 3.0.7 (core)
analytics 1.4.1 (core)
generator 1.1.2 (core)
salesforcedx 47.16.0 (core)
├─ salesforcedx-templates 47.17.0 (core)
└─ salesforce-alm 47.15.0 (core)

sfdx-cli 7.43.1 (core)

OS and version:
Windows 10, 64-bit, version 1903

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/forcedotcom/cli/issues/294?email_source=notifications&email_token=AAQSRPFVIIUD3XO7UICBZATRBCF5LA5CNFSM4KPMSSL2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4IKXBV4A,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AAQSRPF5XQ4BTBBHDUBMLXDRBCF5LANCNFSM4KPMSSLQ
.

Hi aheber,

Thanks for the clarification. I was under the impression that since some sfdx commands could be run from anywhere, then that would not be an issue for the force:source:deploy command as well.

Could the error message be made any more clear? As a suggestion, something like:
"RequiresProjectError: This command is required to run from within folder location, where a sfdx-project.json file exists"

I am sorry for the inconvenience of creating a bug.

Not an inconvenience for me ;)

This error is shown in your output:
This command is required to run from within an SFDX project.

It is buried in the JSON structure as you're requesting that output be returned in JSON format (--json)

Some commands will run from anywhere but there are some that would be ambiguous if they ran from anywhere on your file system. These require the context of a project file to help them understand the intent.

You will also find that default orgs are set as part of the project so any command that allows you to leave off the target username in favor of the default org will also normally not work outside of a project. You can still act on the org using the username or alias but not the ability to leave them off and have the command assume the default org.

Hope that helps. Maybe the CLI team will review this and find options for improvement but my guess is they will close and assume the given error message is sufficient.

@aheber I have a follow-up question, which may be a bit off the original topic:
If I authenticate with the command force:auth:jwt:grant (via a connected app), then I would assume I don't need the defaultusername value in the _sfdx-config.json_ file, and then be able to force:source:deploy - but as such that would leave the _sfdx-config.json_ file empty.

Let me know, if I may write you a direct message to not cloud the correspondence on this topic.

I've reached out on LinkedIn. (I think) Feel free to ping me there.

At a high level, force:auth:jwt:grant adds an available connection to your pool of Auth'd orgs (force:org:list). If you use the --setdefaultusername flag and are not in a project directory it will set it globally (~/.sfdx/sfdx-config.json). If you are in a project directory then it is sets locally to the project only (/.sfdx/sfdx-config.json). So that flag will behave slightly differently depending on your current working directory.

If it is set globally then it is used anytime you are not in a project or that project does not have a defaultusername set on its own.

Normally I don't have a default username at a global level. This is usually because we have different projects running and have different defaults per-project. Haven't really needed a default set at the global level.

Hope that helps.

Was this page helpful?
0 / 5 - 0 ratings