Open shaunc opened 5 years ago
I've run into this as well. vscode correctly identifies TypeScript projects as any directory containing a tsconfig.json
(even if that isn't the workspace directory), but this doesn't carry over to Vue components.
Consider the following:
monorepo/
│
├─ one-package/
│ ├─ src/
│ │ ├─ components/
│ │ │ └─ Header.vue
│ │ ├─ App.vue
│ │ ├─ index.ts
│ │ └─ router.ts
│ │
│ ├─ tsconfig.json
│ └─ package.json
│
├─ second-package/
│ ├─ src/
│ │ ├─ index.ts
│ │ └─ utils.ts
│ │
│ ├─ tsconfig.json
│ └─ package.json
│
├─ lerna.json
└─ vue-shim.d.ts
Both of these tsconfig.json
files would have "paths": { "@/*": ["src/*"] }
. If I open monorepo/
as a workspace in vscode and look at one-package/src/index.ts
, I can use Go to definition while my cursor is sat in '@/router'
and it'll take me to the file. This doesn't involve Vetur though.
I think the issue crops up when:
import App from '@/App.vue'
; or.ts
file or Vue component is imported in a Vue component.vscode still picks up the generic *.vue
definition from vue-shim.d.ts
, but doesn't find the real component. Go to definition just peeks at the shim file.
I get the impression Vetur is built with the assumption that workspace == TypeScript project root, but this isn't strictly true; a TypeScript project is a directory containing a tsconfig.json
. This would presumably involve a fairly wide-reaching refactor to fix. For the time being, open each project in it's own workspace or use Ctrl+P to get around rather than F12.
Edit: FWIW, I think some of the other open tsconfig.json
-related issues are perhaps the same underlying thing.
Same here, even in workspace there's only one package. As long as there's no tsconfig.json
at root of the workspace, Vetur won't work.
Workaround: create a fake tsconfig at root of workspace for Vetur. I don't think it would not work well for multiple packages in monorepo, but might mitigate some error.
{
...
"paths": {
"@/*": ["one-package/src/*", "second-package/src/*"]
}
}
Hi everyone, If you interested this issue, you can go to https://github.com/vuejs/vetur/pull/2377 and https://github.com/vuejs/vetur/pull/2378. View and post your ideas.
Info
Mac OS, Vetur 0.21.1, vscode 1.36.1
Problem
I have a nuxt/typescript project, and can't resolve paths with "~" in vscode. According to documentation, intellisense works from workspace root. However, I am working in a monorepo, with lots of little packages. I prefer not to have workspaces for each. So the workspace root is not the right place to start from. Rather, I would like to resolve tilde from the directory of the first tsconfig.json up from source code. Is there a way to do this? (If not, this is a feature request.)
Reproducible Case