虽然无法让 VS Code 调试器使用不同版本的 Node.js,但可以为 Node.js 的目标版本编译本机模块(如 node-oracledb)。这里有一些细节。
对于 VS Code 1.21.1(使用 Electron 1.7.0),我从扩展目录中的终端执行了以下操作(可能需要先删除该oracledb目录node_modules):
# Electron's version.
export npm_config_target=1.7.0
# The architecture of Electron, can be ia32 or x64.
export npm_config_arch=x64
export npm_config_target_arch=x64
# Download headers for Electron.
export npm_config_disturl=https://atom.io/download/electron
# Tell node-pre-gyp that we are building for Electron.
export npm_config_runtime=electron
# Tell node-pre-gyp to build module from source code.
export npm_config_build_from_source=true
# Install all dependencies, and store cache to ~/.electron-gyp.
HOME=~/.electron-gyp npm install
最后一行启动了一个 npm install ,它为目标平台正确编译了二进制文件(Node.js 7.9.0 的自定义版本,它的 V8 版本比 Node.js 的通常版本更新)。