vuetype
vuetype copied to clipboard
Cannot find type definition file
used the @vue/cli beta to generate a typescript project. I am getting the errors below when I try to generate the type files
Emit Failed: C:\Users\rkk501\Documents\VsCode\t3\t3\src\components\HelloWorld.vue.d.ts Error: Cannot find type definition file for 'jest'. Error: Cannot find type definition file for 'node'.
If is there something in tsconfig I need to change?
Can you provide a reproduction?
sorry for the vague description, create a sample repo
https://github.com/ravirambles/vuetypeissue
If I remove the types
"types": [
"node",
"jest",
"cypress"
],
from the tsconfig.json it is working as expected.
I have the same issue. @ravirambles : Your fix (temporary) works. So I removed "node", "mocha", "chai" from my tsconfig file. I am using vue-cli
I've also gotten around this issue by referencing the types' index.d.ts
files directly:
/// <reference path="../../../../../node_modules/@types/node/index.d.ts" />
Which is of course not a great option. It would seem like the type resolution isn't working at all for that. You may additionally get around it by referencing them in a single .d.ts
file that is either reference
d or import
ed into each file or even possibly added to the typeRoots
list.
Testing other options, I seem to find that it doesn't always fail, as if it may be something to do with incorrect relative paths. For instance, here is the config that I have and the result from running the command:
//tsconfig.json
{
"compilerOptions": {
"target": "es2016",
"module": "commonjs",
"moduleResolution": "node",
"typeRoots": [
"node_modules/@types"
],
"types": [
"node"
]
}
}
$ vuetype --watch app
Emit Failed: app\ui\flat-button.vue.d.ts
Error: Cannot find type definition file for 'node'.
Emit Failed: app\ui\title-bar.vue.d.ts
Error: Cannot find type definition file for 'node'.
Emit Failed: app\ui\forms\labeled-input.vue.d.ts
Error: Cannot find type definition file for 'node'.
Emit Failed: app\windows\credential-window\app\credential-navigation.vue.d.ts
Error: Cannot find type definition file for 'node'.
Emitted: app\windows\credential-window\app\views\credential-landing-view.vue.d.ts
Emitted: app\windows\credential-window\app\views\credential-loading-view.vue.d.ts
Emitted: app\windows\credential-window\app\views\credential-atlassian-view.vue.d.ts
All three of the ones that were successful were at the exact same level, whereas the four that failed were at lower levels. My guess is that it tries to resolve the typing files at specific levels relative to the app root, but that root could be the distance from wherever the /
path would take it (so at the root of the drive for Windows and the root of the computer for Linux/Mac). From counting the distance from the root to the working folder, there are 5 levels each, and referencing the node_modules/@types
fails unless it's exactly 5 levels deep.
I would probably have to look into the source code further before I can say too much about it.
Or potentially more likely, it's due to a race condition, since I made no change and ran it again and only the last two worked, then any subsequent one worked perfectly.
So anyone found the concrete solution here? This is still a problem and removing type definitions from the tsconfig is definitively not an option. Rather the generator should pick them up.
I haven't touched the code I was writing for months, so I am not sure what the workarounds could be.
@ktsn I have a pull request, #29, that fixes this by removing the types from compilerOptions before generating, but the "removes d.ts if corresponding .vue file is removed" test is failing and I'm not sure why.