MDX Error: Can't find typescript.js or tsserverlibrary.js
Checklist
- [X] I have searched through the AstroNvim documentation
- [X] I have searched through the existing issues of this project
- [X] I have searched the existing issues of plugins related to this issue
- [X] I can replicate the bug with the minimal
repro.luaprovided below
Neovim version (nvim -v)
v0.10.1
Operating system/version
macOS 14.5
Terminal/GUI
Alacritty
Describe the bug
I get the following error at the bottom whenever I open a MDX file:
Error executing vim.schedule lua callback: .../neovim/0.10.1/share/nvim/runtime/lua/vim/lsp/client.lua:588: RPC[Error] code_name = InternalError, message = "Request initialize failed with message: Can't find typescript.js or tsserverlibrary.js in \"\""
stack traceback:
[C]: in function 'assert'
.../neovim/0.10.1/share/nvim/runtime/lua/vim/lsp/client.lua:588: in function ''
vim/_editor.lua: in function <vim/_editor.lua:0>
If I escape out of it, everything seems to work fine.
If I do :Mason, I see marksman and mdx-analyzer installed.
Steps to Reproduce
Opening any file with the MDX extension, even if it is empty.
Expected behavior
No error displayed.
Screenshots
No response
Additional Context
No response
Minimal configuration
-- save as repro.lua
-- run with nvim -u repro.lua
-- DO NOT change the paths
local root = vim.fn.fnamemodify("./.repro", ":p")
-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "runtime", "cache" }) do
vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end
-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
-- stylua: ignore
vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", "--branch=stable",
lazypath })
end
vim.opt.rtp:prepend(vim.env.LAZY or lazypath)
-- install plugins
local plugins = {
{ "AstroNvim/AstroNvim", import = "astronvim.plugins" },
{ "AstroNvim/astrocommunity", import = "astrocommunity.pack.mdx" },
-- add any other plugins/customizations here
}
require("lazy").setup(plugins, {
root = root .. "/plugins",
})
-- add anything else here (autocommands, vim.filetype, etc.)
@nickali Please provide a repro.lua
@Uzaaft, I updated the minimal configuration above.
Appreciate it :)
The same issue with 'tsserver' in Vue files if project doesn't exist TS
Error executing vim.schedule lua callback: .../neovim/0.10.1/share/nvim/runtime/lua/vim/lsp/client.lua:588: RPC[Error] code_name = InternalError, message = "Request initialize failed with message: Can't find typescript.js or tsserverlibrary.js in \"/Users/qmpwwsd/Desktop/smartgroups/smartchat-ui/node_modules/typescript/lib\""
stack traceback:
[C]: in function 'assert'
.../neovim/0.10.1/share/nvim/runtime/lua/vim/lsp/client.lua:588: in function ''
vim/_editor.lua: in function <vim/_editor.lua:0>
@nickali did you find how fix it?
@nickali did you find how fix it?
No.
Same issue here, every time I open an MDX file I get that error. I noticed the error message says:
...Can't find typescript.js or tsserverlibrary.js in \"......(my project root folder) /node_modules/node_modules/typescript/lib\"
Which appears to be one too many node_modules directories. But I can't figure out which LSP client/plugin/config where this path is being set...
Seems related to https://github.com/williamboman/mason-lspconfig.nvim/issues/351 upstream issue?
Related to too many node_modules directories.
For my monorepo project
root
| - pkgA
| | - node_modules/ # [Empty Directory]
| | - file.mdx
| - pkgB
| | - node_modules/ # [Empty Directory]
| - node_modules/ # [All pkg goes here]
when file.mdx setting up lsp, inspect mdx_analyzer's on_new_config func, the input attr new_root_dir is root/pkgA and the return value is same. modify func get_typescript_server_path resolved the issue as it only detects node_modules directory exists or not.
https://github.com/neovim/nvim-lspconfig/blob/9e932edb0af4e20880685ddb96a231669fbe8091/lua/lspconfig/configs/mdx_analyzer.lua#L3
Edit config to
local function get_typescript_server_path(root_dir)
local project_root = vim.fs.dirname(vim.fs.find("node_modules/typescript/lib", { path = root_dir, upward = true })[1])
return project_root and (project_root .. "/lib") or ""
end
require("lspconfig").mdx_analyzer.setup({
on_attach = on_attach,
capabilities = capabilities,
on_new_config = function(new_config, new_root_dir)
if vim.tbl_get(new_config.init_options, "typescript") and not new_config.init_options.typescript.tsdk then
new_config.init_options.typescript.tsdk = get_typescript_server_path(new_root_dir)
end
end,
})