You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VSCode打开Salesforce LWC项目时JSON/ESLint服务连接失败求助

解决VSCode打开LWC项目时JSON语言服务与ESLint服务连接失败问题

错误详情

JSON语言服务错误输出

2024-12-06 17:45:47.112 [info] [Error - 5:45:47 PM] JSON Language Server client: couldn't create connection to server.
2024-12-06 17:45:47.112 [info] TypeError: this._getServerWorkingDir(...).then(...).finally is not a function
    at t.activate (c:\Users\username\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\json-language-features\client\dist\node\jsonClientMain.js:1:576318)

ESLint服务错误输出

[Info  - 5:45:46 PM] ESLint server is starting.
[Info  - 5:45:46 PM] ESLint server stopped.
[Error - 5:45:46 PM] ESLint client: couldn't create connection to server.
TypeError: this._getServerWorkingDir(...).then(...).finally is not a function
    at Object.MessagePortMain._internalPort.emit (node:electron/js2c/utility_init:2:2949)
[Error - 5:45:46 PM] Starting the server failed.
TypeError: this._getServerWorkingDir(...).then(...).finally is not a function
    at Object.MessagePortMain._internalPort.emit (node:electron/js2c/utility_init:2:2949)

解决方案

核心原因是Node.js版本过低,Promise.prototype.finally特性需要Node.js 10.0.0及以上版本支持,VSCode内置或系统的Node版本不满足要求导致服务启动失败。

  • 升级系统Node.js版本

    1. 打开终端执行 node -v 检查当前版本
    2. 若版本低于10.0.0,安装最新稳定版(建议16.x及以上,适配LWC开发需求)
    3. 安装完成后重启VSCode,重新打开项目
  • 指定VSCode使用的Node.js版本

    1. 打开VSCode设置(快捷键Ctrl+,)
    2. 搜索「Node Path」,找到「JSON: Node Path」和「ESLint: Node Path」设置项
    3. 填入已安装的高版本Node.js可执行文件路径(例如C:\Program Files\nodejs\node.exe)
    4. 保存设置后重启VSCode
  • 清除VSCode扩展缓存

    1. 关闭VSCode
    2. 删除对应缓存目录:
      • Windows:%APPDATA%\Code\Cache 和 %APPDATA%\Code\CachedData
      • macOS:~/Library/Application Support/Cache 和 ~/Library/Application Support/CachedData
    3. 重新打开VSCode加载项目
  • 重装ESLint扩展

    1. 在VSCode扩展面板找到ESLint,点击「卸载」
    2. 重启VSCode后重新安装ESLint扩展
    3. 打开项目等待扩展初始化完成

内容的提问来源于stack exchange,提问作者CodeMed

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.15 20:02:41