salesforcedx-vscode: Cannot read property 'fspath' of undefined --> when using a Keyboard shortcut to deploy Salesforce file
I added a custom keyboard shortcut to deploy current file using “sfdx.force.source.deploy.current.file” command
One of our business requirements is to figure out a keyboard shortcut that can do Save and compile of Apex classes from VSCode while doing ORG based development. This is very important for us to roll out VSCode and drive adoption of its use for Salesforce development. This feature is currently not available in VSCode and hence I tried adding a keyboard shortcut for the sfdx command but I am running into an issue.
Steps To Reproduce:
- Go to Code --> Preferences --> Keyboard Shortcuts

- Open keybindings.json file

- Add the below command in your keybindings.json file
[ { "key": "shift+cmd+r", "command": "sfdx.force.source.deploy.current.file" } ]
- This is how your keybindings.json file should look like

- Now open an Apex class or Visualforce page or Trigger file and press Shift+Cmd+r
Expected result
The file should have been deployed
Actual result

VS Code Version:

SFDX CLI Version:

OS and version:

Other Commands just work perfectly fine, for e.g.
[ { "key": "shift+cmd+r", "command": "sfdx.force.org.open" } ]

About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 5
- Comments: 58 (18 by maintainers)
Commits related to this issue
- Fixed file path to allow keyboard shortcuts. Fixes #662 — committed to forcedotcom/salesforcedx-vscode by deleted user 5 years ago
One of my colleagues found a good way to do this:
Output: hit “cmd+shift+b” (in MacOS), it will do
Steps
Save on deploy is going out in our next release.
@ntotten @lcampos Dug around a bit and saw the error was caused by line 49 in https://github.com/forcedotcom/salesforcedx-vscode/blob/develop/packages/salesforcedx-vscode-core/src/commands/forceSourceRetrieve.ts
Changing the constructor from this,
to,
seems to do the trick.
Would like to know any possible downsides to this fix. Thanks.
Hi all - we’re taking a look at “Cannot read property ‘fsPath’ of undefined” with a new issue #3656 - feel free to add any additional details there. (Deploy on save issues we’re tracking on #3655 and are currently working on a fix for that one.) Thanks for your comments and patience!
Passed 4 months and the “bug” exist yet, @Xixiao007 gave the perfect solution for this problem: https://github.com/forcedotcom/salesforcedx-vscode/issues/662#issuecomment-439354751
Why SF don’t update it yet 😦?
@Anaatoole fix did not work for me. Still broken.
Wow that worked for me! Thank you @Anaatoole!
This issue appears to be broken again. I updated VSCode today and it now gives me the same error. Was working previously.
push/deploy on save is not a viable alternative for many, including myself. Many plugins can cause the file to save (such as editorconfig), plus many people have a habit of frequently saving their code, way before its compilable and ready to push to an org.
Deploy on save is a good feature for those that want it, but it is not really a reliable alternative to having a shortcut that ONLY deploys, when the developer is ready.
Just my opinion of course!
@randi274 I am on 53.4.2 and was on that version when I posted earlier today, but it was fixed only after I updated the CLI today. Since it appears to be fixed, it’s probably fine but it appears to not be perfect based on this. I updated the CLI from 122 to 124. Don’t remember the rest of the version numbers, but that’s all that fixed it for me.
For me just reload twice VS Code worked.
I started getting this error today too. Yesterday it worked fine. I had to disable deploy on save and right click on a file to deploy.
+1 on this issue. I can see a pull request waiting to be approved, hopefully it will be released soon so we can optimise our workflows. Huge thanks to the devs who are working on the fix.
@lcampos Hiya, just a quick follow up re the tooling API. While I get that it doesn’t support all metadata types, you should definitely consider enabling it just for those types that it does. Though I’m sure you have… You guys know what you’re doing. (I’m kind of an idiot…)
Anyhoo… I have recently installed the SalesforceDX Code Companion extension. It uses an sfdx plugin he built which provides new commands to save/retrieve using the Tooling API, and I’ve gotta say… it’s now all I use (for Apex anyway).
Ctrl-shift-c for the win. Now, I’m happy. I was honestly having a hard time being productive with the deploy to save.
Just my experience…
Anyways, keep up the great work guys!
@JamieBriersSageCom Makes sense, thanks for the explanation. I will reopen for us to implement or to accept a PR.
hi @Xtremefaith, using a keybinding for existing deploy commands won’t work because of limitations on how to define it and the commands depending on a filepath to be provided. We explored the possibility of changing the commands to show a quick-pick option, when no filepath was provided, and then choose the file/folder you wanted to deploy. We discarded that because of how unmanageable it became when working on medium-to-large projects and decided to invest time in releasing the current deploy on save functionality. If this is something you really want I’d suggest opening a feature request (a new issue) for it.
As to how deploy on save works, it deploys only the file that you save. E.g. if you are modifying an apex class and save it, it will wait for a few seconds to see if you’re done editing it and will then deploy the file.