forcedotcom / salesforcedx-vscode

Salesforce Extensions for VS Code
https://developer.salesforce.com/tools/vscode
BSD 3-Clause "New" or "Revised" License
954 stars 406 forks source link

Vs Code Extension Error Initializing #5069

Closed salesforceProDev closed 1 year ago

salesforceProDev commented 1 year ago

Summary

On VScode loading getting this error all the time: Request initialize failed with message: Cannot read properties of undefined (reading 'location') (Lightning Web Components Extension)

Steps To Reproduce:

  1. Open VsCode.
  2. Let the extensions initialize
  3. There is error on the bottom right corner "Request initialize failed with message: Cannot read properties of undefined (reading 'location')"

Expected result

There should be no error the vsCode extensions should initialize without any error

Actual result

Getting error: Request initialize failed with message: Cannot read properties of undefined (reading 'location')

Additional information

Tried to uninstall and install all the extensions back, but didn't work.

Screenshot 2023-09-02 110217

Salesforce Extension Version in VS Code:

salesforce.salesforcedx-vscode-lwc --> version: v58.14.1

SFDX CLI Version: sfdx-cli/7.209.6 win32-x64 node-v18.15.0

OS and version: Window 11 64bit

bobalicious commented 1 year ago

@CristiCanizales - this ticket has had the label 'stale' added to it - and whilst the ticket may have had a low level replies from yourselves over the last week or so, it is still my understanding that it is active and should remain open. Can the label be removed?

CristiCanizales commented 1 year ago

@JsalvaJ It was supposed to be solved but now it seems like it isn't. We're still investigating and will update once we have a new fix!

gbockus-sf commented 1 year ago

Howdy @bobalicious @JsalvaJ @Razvan-Racolta I built a debug version of the LWC extension with logging around when a location property is accessed. If you could download from my fork and attempt to generate the debug logging to give us an idea of where the failure is occurring that would be awesome. Find instructions and vsix in the below release. https://github.com/gbockus-sf/salesforcedx-vscode/releases/tag/0.0.3

I'm pretty sure the issue is something about how exports are structured, but haven't been able to repo based on the LayoutConstants example above.

Thanks for your patience on this.

bobalicious commented 1 year ago

lwc-language-server-log-23-10-19-0912.txt

gbockus-sf commented 1 year ago

Thanks for the log @bobalicious Comparing it to my run locally I needed to add more info to the logs to find out where exactly the error is occurring. It appears to be making it all the way through the property and method analysis.

I uploaded a new version of the vsix here If you could send me those logs that'd be awesome.

Also if you could email me (gbockus@salesforce.com) the LWC that is resulting in the error and I could try to repo locally that'd speed this along for sure

   "name": "LoadEntityForm",
    "id": "Class#LoadEntityForm#15",

If not possible I totally get that. Thanks!

bobalicious commented 1 year ago

It'll be a few days before I'll be able to do that, but I will certainly try.

Knowing which LWC is causing the problem to appear, I may be able to reduce the test case and provide a version that is less, shall we say, private. I'll catch up with this again next week.

bobalicious commented 1 year ago

Reproduction using the new VSIX

With the version referenced above installed, I do not get an 'LWC Language Server' output window.

There is an 'LWC Extension' output window that contains no logs whatsoever.

I can see no other output windows that contain any debug logs of the type you are looking for.

The 'Extension Host' output window contains:

2023-10-30 11:10:04.500 [error] Error: Request initialize failed with message: Cannot read properties of undefined (reading 'location')
    at handleResponse (/Users/xxx/.vscode/extensions/salesforce.salesforcedx-vscode-lwc-59.0.1/dist/index.js:8728:40)
    at processMessageQueue (/Users/xxx/.vscode/extensions/salesforce.salesforcedx-vscode-lwc-59.0.1/dist/index.js:8583:13)
    at Immediate.<anonymous> (/Users/xxx/.vscode/extensions/salesforce.salesforcedx-vscode-lwc-59.0.1/dist/index.js:8569:11)
    at processImmediate (node:internal/timers:476:21)

Replication using the LoadEntityForm LWC

I have attempted to replicate the issue using only the LoadEntityForm LWC and it does not occur with that LWC, and so I am not forwarding it on to you.

bobalicious commented 1 year ago

@gbockus-sf / @CristiCanizales - I believe I've found the shape of LWC that causes the issue.

It is a pattern where you create a setter but no corresponding getter.

  1. Create a new LWC
  2. Add a property
  3. Add a setter for that property with a slightly different name
  4. DO NOT add a getter
  5. Save
  6. Witness the crash

E.g. an LWC that consists solely of the following:

import { LightningElement } from 'lwc';

export default class PropertySetterWithNoGetter extends LightningElement {

    _property = '';
    set property( value ) {
        this._property = value;
    }
}

Please do not discuss as to why this would be desirable - it is a perfectly valid block of code and I am aware that there are other ways of doing the same thing. This example exists purely to show how to get the Lightning Web Components extension to crash.

(Note: this pattern did not exist in LoadEntityForm, it was in an entirely different LWC, so I'm not sure what happened with the logging)

gbockus-sf commented 1 year ago

💥 Thanks @bobalicious I repo'd locally and will see what we can do to get it resolved.

git2gus[bot] commented 1 year ago

This issue has been linked to a new work item: W-14391061

gbockus-sf commented 1 year ago

Fixed with the 59.3.1 Release. Thanks for working with us to get this issue resolved. 🥳 🎉

bobalicious commented 1 year ago

Confirmed as fixed from my perspective