mtxr / vscode-sqltools

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

nodeJS syntax error prevents SQLTools from being functional #1024

Closed GegznaV closed 1 year ago

GegznaV commented 1 year ago

Describe the bug Error occurs if nodeJS runtime is enabled.

To Reproduce Steps to reproduce the behavior: 1.Set "sqltools.useNodeRuntime": true

  1. Reload VSCode
  2. A new default terminal gets opened at VSCode startup:
    image
  3. An error similar to this occurs (in the example Command Prompt is the default terminal) is present in the terminal:
D:\dir>node -e 'require(\"fs\").writeFileSync(\"C:\\Users\\user\\AppData\\Local\\vscode-sqltools\\Data\\.node-runtime\", process.execPath)' && exit 0     Data\\.node-runtime\", process.execPath)' && exit 0
[eval]:1
'require("fs").writeFileSync("C:\\Users\\user\\AppData\\Local\\vscode-sqltools\\Data\\.node-runtime",
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

SyntaxError: Invalid or unexpected token
    at new Script (node:vm:100:7)
    at createScript (node:vm:265:10)
    at Object.runInThisContext (node:vm:313:10)
    at node:internal/process/execution:79:19
    at [eval]-wrapper:6:22
    at evalScript (node:internal/process/execution:78:60)
    at node:internal/main/eval_string:28:3

Node.js v18.12.0

The list of currently set connections is not present image

After pushing "Add New Connection" and a pal period (e.g., 1 min.) additional error occurs as a pop-up: image

Expected behavior No error, fully functional SQLTools extension.

Desktop (please complete the following information):

Additional context This issue appeared when I tried to connect to an SQLite database.

gjsjohnmurray commented 1 year ago

Please see https://github.com/mtxr/vscode-sqltools/pull/993#issuecomment-1265828891 for advice. Let us know if this helps.

Ocraftyone commented 1 year ago

The issue seems to be the use of single quotes rather than double. If you change the quotes to double it executes. Edit: following that comment above does fix this, but only as a workaround. The auto detect still does not work. I am using Command Prompt

GegznaV commented 1 year ago

Installing PowerShell 7 and setting it as the default terminal for windows in VSCode worked for me. But does it mean that I am forced to use these settings to make the plugin work? I'd like to use Git Bash or Ubuntu WLS terminal as the default terminal.

GegznaV commented 1 year ago

OK, there is more in that comment. I did not use that workaround yet.

GegznaV commented 1 year ago

Setting to "sqltools.useNodeRuntime": "C:\\Program Files\\nodejs\\node.exe" and using WSL terminal as default gives the same issue as in the original post.

GegznaV commented 1 year ago

So

But does it mean that I am forced to use these settings to make the plugin work? I'd like to use Git Bash or Ubuntu WLS terminal as the default terminal.

gjsjohnmurray commented 1 year ago

Today's 0.26.0 release includes changes that should make this mechanism work even without PowerShell 7. Please let us know here if this helps you.

GegznaV commented 1 year ago

I did not change anything, just updated the plugins (use PowerShell 7 as the default shell on the Windows side). Is this warning expected at VSCode startup?

image

GegznaV commented 1 year ago

Does this message mean to change this setting "sqltools.useNodeRuntime"?

Can the purpose described in the message be achieved by deleting "sqltools.useNodeRuntime": "C:\\Program Files\\nodejs\\node.exe" from settings.json?

GegznaV commented 1 year ago

OK, the removal of this setting did not help to remove the warning. Please, give more explicit instructions on what to do to get rid of this warning.

mikes-gh commented 1 year ago

0.26 with powershell 7 on macOS

PS /Users/mikes/Documents/Repos/Workflows> node -e 'require("fs").writeFileSync("/Users/mikes/Library/Application Support/vscode-sqltools/.node-runtime", process.execPath)'
[eval]:1
require(fs).writeFileSync(/Users/mikes/Library/Application
                          ^

SyntaxError: Invalid regular expression flags
    at new Script (node:vm:101:7)
    at createScript (node:vm:262:10)
    at Object.runInThisContext (node:vm:310:10)
    at node:internal/process/execution:77:19
    at [eval]-wrapper:6:22
    at evalScript (node:internal/process/execution:76:60)
    at node:internal/main/eval_string:23:3
PS /Users/mikes/Documents/Repos/Workflows> 
gjsjohnmurray commented 1 year ago

@mikes-gh what version of node do you have?

node -v

mikes-gh commented 1 year ago

@mikes-gh what version of node do you have?

node -v

v15.3.0

edit

Same error with v18.12.1

mikes-gh commented 1 year ago

On my machine macOS powershell 7 and I suspect Linux

node -e 'require("fs").writeFileSync("/Users/mikes/Library/Application Support/vscode-sqltools/.node-runtime", process.execPath)' && $(exit 0) Result error

node -e "require('fs').writeFileSync('/Users/mikes/Library/Application Support/vscode-sqltools/.node-runtime', process.execPath)" && $(exit 0) Result succeed

mikes-gh commented 1 year ago

Can someone on windows try

node -e "require('fs').writeFileSync('C:\ChangeThisToYourPath\vscode-sqltools\.node-runtime', process.execPath)" && $(exit 0)

And if it works just change.

https://github.com/gjsjohnmurray/vscode-sqltools/blob/b13607e1b77049200b897f30bfe4e9033ee3a6bc/packages/extension/src/language-client/detect-node-path.ts#L20

gjsjohnmurray commented 1 year ago

OK, the removal of this setting did not help to remove the warning. Please, give more explicit instructions on what to do to get rid of this warning.

@GegznaV when sqltools.useNodeRuntime is set to be a string I wouldn't expect that modal warning ever to appear. When set true the modal will appear after 5 seconds if detection hasn't completed. I have created #1034 to increase this timeout. Until then I suggest you either tolerate it, or set the string, or get a faster workstation. 😉

GegznaV commented 1 year ago

Thank you for your response, @gjsjohnmurray :)

GegznaV commented 1 year ago

OK, the removal of this setting did not help to remove the warning. Please, give more explicit instructions on what to do to get rid of this warning.

@GegznaV when sqltools.useNodeRuntime is set to be a string I wouldn't expect that modal warning ever to appear. When set true the modal will appear after 5 seconds if detection hasn't completed. I have created #1034 to increase this timeout. Until then I suggest you either tolerate it, or set the string, or get a faster workstation. 😉

In my settings, there was null, not logical:

"sqltools.useNodeRuntime": null

Do you mean string like this:

image

If yes, why does the warning appear?

GegznaV commented 1 year ago

Until then I suggest you either tolerate it

No problem :)


For me, the initial issue is solved. So, in my opinion, the thread can be closed.

Just I'm not sure about @mikes-gh's issue: is it solved too? Is it the same issue?

gjsjohnmurray commented 1 year ago

@GegznaV in the JSON in your screenshot the word sqltools has squiggles under it. Do you get a tip when you hover over the word? Which settings file is this in?

I don't know why null is also an accepted value for this setting. @mtxr may do.

gjsjohnmurray commented 1 year ago

Just I'm not sure about @mikes-gh's issue: is it solved too? Is it the same issue?

That's different. I created #1036 for it.

GegznaV commented 1 year ago

JSON in your screenshot the word sqltools has squiggles under it.

It is a spellchecker: image

GegznaV commented 1 year ago

I don't know why null is also an accepted value for this setting.

I deleted the row from the settings, and the one with null was auto-generated.

GegznaV commented 1 year ago

Which settings file is this in?

Ctrl+Shift+P then: image

gjsjohnmurray commented 1 year ago

Do you have a workspace open? If yes there will also be a command Preferences: Open Workspace Settings (JSON). Please run that and check whether you have any sqltools settings in it.

GegznaV commented 1 year ago

In "sqltools.useNodeRuntime": "C:\\Program Files\\nodejs\\node.exe" there was a logical value. I fixed it into character and the issue got fixed. Thank you, @gjsjohnmurray :)