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版本
- 打开终端执行
node -v检查当前版本 - 若版本低于10.0.0,安装最新稳定版(建议16.x及以上,适配LWC开发需求)
- 安装完成后重启VSCode,重新打开项目
- 打开终端执行
指定VSCode使用的Node.js版本
- 打开VSCode设置(快捷键
Ctrl+,) - 搜索「Node Path」,找到「JSON: Node Path」和「ESLint: Node Path」设置项
- 填入已安装的高版本Node.js可执行文件路径(例如
C:\Program Files\nodejs\node.exe) - 保存设置后重启VSCode
- 打开VSCode设置(快捷键
清除VSCode扩展缓存
- 关闭VSCode
- 删除对应缓存目录:
- Windows:
%APPDATA%\Code\Cache和%APPDATA%\Code\CachedData - macOS:
~/Library/Application Support/Cache和~/Library/Application Support/CachedData
- Windows:
- 重新打开VSCode加载项目
重装ESLint扩展
- 在VSCode扩展面板找到ESLint,点击「卸载」
- 重启VSCode后重新安装ESLint扩展
- 打开项目等待扩展初始化完成
内容的提问来源于stack exchange,提问作者CodeMed
相关产品推荐
相关产品推荐

