0

This is my first time trying to set up lazy-vim for javascript/typescript development. I have followed multiple blog posts and youtube channel to set things up. And it is working so far. Only problem is, the typescript lsp server is not able to resolve absolute imports relative to source folder.

Thanks for help.

Following are the contents of my jsconfig.json -


{
    "compilerOptions": {
        "module": "commonjs",
        "target": "es6",
        "baseUrl": "src/",
        "jsx": "react"
    },
    "include": ["src"]
}

Following is my typescript lsp setup -

 typescript.setup({
      go_to_source_definition = {
        fallback = true,
      },
      debug = false,
      disable_commands = false,
      server = {
        capabilities = capabilities,
        on_attach = on_attach,
      },
    })
  • 1
    "resolve absolute imports relative to source folder" this makes no sense: file paths are either relative or absolute (and you should basically never use an absolute path for a JS import). Please give an example of the import you are struggling with along with the relevant directory structure and what directory you were in when you started neovim. – Jared Smith Aug 30 '23 at 16:24
  • @JaredSmith I have folder named components in src, I amd importing Custom Button as `import CustomButton from 'components/CustomButton'`, but it does not recognize the import. If I import using `../components/CustomButton` it works. I need the first way to work, as my pages have a lot of nested folders. – Sumit Khaitan Aug 31 '23 at 10:31
  • ...that has nothing to do with neovim or the TS LSP: Javascript/Typescript imports do not work that way. One alternative to lengthy relative paths would be to use some form of monorepo management tool (like yarn workspaces) and make them named packages that you can import across the monorepo. But you can't just arbitrarily change how the [node resolution algorithm](https://www.typescriptlang.org/docs/handbook/module-resolution.html) works. – Jared Smith Aug 31 '23 at 19:43
  • @JaredSmith thanks for the reply, will look in that direction. – Sumit Khaitan Sep 01 '23 at 05:02

0 Answers0