Skip to content
This repository has been archived by the owner on May 7, 2024. It is now read-only.

Support latest LTS node@18 or latest node #334

Open
Troublor opened this issue Dec 13, 2022 · 12 comments
Open

Support latest LTS node@18 or latest node #334

Troublor opened this issue Dec 13, 2022 · 12 comments

Comments

@Troublor
Copy link

The current implementation requires node@16: https://github.com/znck/grammarly/blob/main/package.json#L4

When starting grammarly-languageserver with node@18 or node@19, there appears a runtime error if it is attached to a markdown file:

TypeError: Failed to parse URL from /path/to/grammarly-languageserver/node_modules/web-tree-sitter/tree-sitter.wasm
    at Object.fetch (node:internal/deps/undici/undici:14294:11) {
  [cause]: TypeError [ERR_INVALID_URL]: Invalid URL
      at new NodeError (node:internal/errors:393:5)
      at URL.onParseError (node:internal/url:565:9)
      at new URL (node:internal/url:645:5)
      at new Request (node:internal/deps/undici/undici:7023:25)
      at fetch2 (node:internal/deps/undici/undici:13460:25)
      at Object.fetch (node:internal/deps/undici/undici:14292:18)
      at fetch (node:internal/process/pre_execution:238:25)
      at /path/to/grammarly-languageserver/node_modules/web-tree-sitter/tree-sitter.js:1:15192
      at /path/to/grammarly-languageserver/node_modules/web-tree-sitter/tree-sitter.js:1:15413
      at new Promise (<anonymous>) {
    input: '/path/to/grammarly-languageserver/node_modules/web-tree-sitter/tree-sitter.wasm',
    code: 'ERR_INVALID_URL'
  }
}

It seems to be breaking change in node@18 related to URL.

Is it possible that grammarly gets updated an support the latest node?


This issue originated from Homebrew/homebrew-core#118003, which patches the grammarly-languageserver formula by sticking to node@16 and avoids this issue temporarily.

@AndreasNasman
Copy link

I encountered the same problem, trying to get Grammarly working with Neovim using Mason and Node v18. Downgrading to Node v16 with nvm got rid of the ERR_INVALID_URL error.

Node v18 is the current LTS version as of 2022-10-25, so I think more people will run into this problem. Upgrading would resolve Need help configuring the language server with neovim (the most upvoted discussion in this repo) and close #336 🙂

@Troublor
Copy link
Author

I contributed a homebrew formula for grammarly-languageserver, which use Node@16 internally.
https://formulae.brew.sh/formula/grammarly-languageserver
It eliminates the need to adjust the node version in the shell that runs nvim.

@gcstr
Copy link

gcstr commented Jan 11, 2023

That's weird. I'm on node 16 and still I see the same issue.

@Troublor
Copy link
Author

That's weird. I'm on node 16 and still I see the same issue.

Can you be sure that the Neovim really uses node16 to launch grammarly-languageserver? I encounter situations where Neovim does not uses the node in my shell environment.

@gcstr
Copy link

gcstr commented Jan 12, 2023

Sure, here is the error log:

[ERROR][2023-01-11 18:24:22] .../vim/lsp/rpc.lua:733	"rpc"	"grammarly-languageserver"	"stderr"	"node:internal/deps/undici/undici:14152\n    Error.captureStackTrace(err, this);\n          ^\n\nTypeError: Failed to parse URL from /Users/gustavocastro/.local/share/nvim/mason/packages/grammarly-languageserver/node_modules/grammarly-languageserver/node_modules/web-tree-sitter/tree-sitter.wasm\n    at Object.fetch (node:internal/deps/undici/undici:14152:11) {\n  [cause]: TypeError [ERR_INVALID_URL]: Invalid URL\n      at new NodeError (node:internal/errors:399:5)\n      at URL.onParseError (node:internal/url:565:9)\n      at new URL (node:internal/url:645:5)\n      at new Request (node:internal/deps/undici/undici:6947:25)\n      at fetch2 (node:internal/deps/undici/undici:13315:25)\n      at Object.fetch (node:internal/deps/undici/undici:14150:18)\n      at fetch (node:internal/process/pre_execution:241:25)\n      at /Users/gustavocastro/.local/share/nvim/mason/packages/grammarly-languageserver/node_modules/grammarly-languageserver/node_modules/web-tree-sitter/tree-sitter.js:1:15192\n      at /Users/gustavocastro/.local/share/nvim/mason/packages/grammarly-languageserver/node_modules/grammarly-languageserver/node_modules/web-tree-sitter/tree-sitter.js:1:15413\n      at new Promise (<anonymous>) {\n    input: '/Users/gustavocastro/.local/share/nvim/mason/packages/grammarly-languageserver/node_modules/grammarly-languageserver/node_modules/web-tree-sitter/tree-sitter.wasm',\n    code: 'ERR_INVALID_URL'\n  }\n}\n\nNode.js v19.4.0\n"

And here is the :checkhealth output:
Screenshot 2023-01-12 at 19 54 31

@Troublor
Copy link
Author

@gcstr Sorry, I have no idea then.

@AndreasNasman
Copy link

@gcstr If you scroll to the far right of your log you can see that Node v.19.4.0 is being used 👇

code: 'ERR_INVALID_URL'\n }\n}\n\nNode.js v19.4.0\n"

@gcstr
Copy link

gcstr commented Jan 21, 2023

I just found out that if I omit the clientId Grammarly works, but when I pass it to the configuration, it complains with that weird error.

  lsp.configure("grammarly", {
    init_options = { clientId = "client_[redacted]" }
  })

I say it's weird because I don't have node v19.04 installed. I removed all node versions, installed node@16, reinstalled all nvim plugins, and did the same with LSPs and I'm still getting the error above when setting up with my clientId

@Himujjal
Copy link

Himujjal commented Apr 7, 2023

Hack till this issue is solved in your ~/.zshrc or ~/.bashrc:

First install Node v16:

nvm install v16.14.0

Add the following to your shell configuration:

function nvim2() {
    export NVIM_BIN=$(which nvim)
    export NODE_CURRENT=$(node -v)
    nvm use v16.14.0 
    $NVIM_BIN $@
    nvm use $NODE_CURRENT
}

Then execute

nvim2 README.md

Will be a little bit slow at first. But eh! This issue is also temporary. Delete the above function later on once this issue is solved

@mbekkomo
Copy link

mbekkomo commented Aug 7, 2023

For me, I used n to switch between NodeJS version.

First, download (not install) NodeJS v16.

n -d 16

Second, set cmd property of grammarly configuration to { "n", "run", "16", "path/to/grammarly-languageserver", "--stdio" }.

require("lspconfig").grammarly.setup {
  cmd = { "n", "run", "16", "path/to/grammarly-languageserver", "--stdio" },
}

path/to/grammarly-languageserver is path to where you've installed the langserver. To check where it's located, run which grammarly-languageserver.

And now test it with random markdown file.

nvim README.md

@gvegayon
Copy link

I can confirm the bug. Changing the extension of the file to something else like qmd and restarting VS works.

@LeonardoMor
Copy link

LeonardoMor commented Dec 17, 2023

For me, I used n to switch between NodeJS version.

First, download (not install) NodeJS v16.

n -d 16

Second, set cmd property of grammarly configuration to { "n", "run", "16", "path/to/grammarly-languageserver", "--stdio" }.

require("lspconfig").grammarly.setup {
  cmd = { "n", "run", "16", "path/to/grammarly-languageserver", "--stdio" },
}

path/to/grammarly-languageserver is path to where you've installed the langserver. To check where it's located, run which grammarly-languageserver.

And now test it with random markdown file.

nvim README.md

Similarly, for those of us that use nvm, after installing Node 16, save this into ~/bin/grammarlywo.sh:

#!/usr/bin/env bash
source "${NVM_DIR}/nvm.sh"
nvm run 16 path/to/grammarly-languageserver --stdio

And make it executable.

Then the command to call Grammarly would be:
cmd = { os.getenv("HOME") .. "/bin/grammarlywo.sh" },

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants