mtxr / vscode-sqltools

Database management for VSCode
https://vscode-sqltools.mteixeira.dev?utm_source=github&utm_medium=homepage-link
MIT License
1.49k stars 299 forks source link

Node path detection error on Windows (using Command prompt as default Terminal) #1042

Closed strikehawk closed 1 year ago

strikehawk commented 1 year ago

I get this error every time I start VS Code with SQLTools extension enabled

F:\<MY PATH>>node -e 'require(\"fs\").writeFileSync(\"C:\\Users\\<USERNAME>\\AppData\\Local\\vscode-sqltools\\Data\\.node-runtime\", process.execPath)' && exit 0
[eval]:1
'require("fs").writeFileSync("C:\\Users\\<USERNAME>\\AppData\\Local\\vscode-sqltools\\Data\\.node-runtime",
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

SyntaxError: Invalid or unexpected token
    at new Script (node:vm:100:7)
    at createScript (node:vm:257:10)
    at Object.runInThisContext (node:vm:305:10)
    at node:internal/process/execution:75:19
    at [eval]-wrapper:6:22
    at evalScript (node:internal/process/execution:74:60)
    at node:internal/main/eval_string:27:3

Issue similar to:

Desktop (please complete the following information):

Additional context I have set 'Command prompt' as my default Terminal.

Issue seems to be related to quote management when issuing the command to the terminal, at this line: https://github.com/mtxr/vscode-sqltools/blob/b1e982f776d103e768b100e24610e3eba9f56f9e/packages/extension/src/language-client/detect-node-path.ts#L22

Replacing

      terminal.sendText(`node -e '${process.platform === 'win32' ? nodeCmdWindows : nodeCmd}' ${shellExitCommand}`);

with

      if (process.platform === 'win32') {
        terminal.sendText(`node -e "${nodeCmdWindows}" ${shellExitCommand}`);
      } else {
        terminal.sendText(`node -e '${nodeCmd}' ${shellExitCommand}`);
      }

in the source code of the extension solves the issue on my machine, but I did not conduct intensive tests.

theAkito commented 1 year ago

According to this comment, the location of the Node runtime is only needed, if one uses the SQLite functionality. Well, I installed the extension exactly for that.

Essentially, I only have the choice to disable the SQLite functionality altogether or face these errors on each startup, for each Visual Studio Code window, that opens. Unbearable.

I use a custom login shell in WSL2 on Windows 10.

So, the solution to these issues, i.e. this one and the ones that are linked here, must be fairly generic and not specific to bash or Git Bash or whatever there is. It must work with anything, as long as the target shell/environment supports the standard commands for looking up something.