vuetype icon indicating copy to clipboard operation
vuetype copied to clipboard

Cannot find type definition file

Open ravirambles opened this issue 6 years ago • 10 comments

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?

ravirambles avatar Apr 21 '18 17:04 ravirambles

Can you provide a reproduction?

ktsn avatar Apr 22 '18 01:04 ktsn

sorry for the vague description, create a sample repo

https://github.com/ravirambles/vuetypeissue

ravirambles avatar Apr 22 '18 13:04 ravirambles

If I remove the types

"types": [
  "node",
  "jest",
  "cypress"
],

from the tsconfig.json it is working as expected.

ravirambles avatar Apr 26 '18 12:04 ravirambles

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

ghost avatar May 06 '18 09:05 ghost

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 referenced or imported into each file or even possibly added to the typeRoots list.

cwadrupldijjit avatar Aug 03 '18 20:08 cwadrupldijjit

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.

cwadrupldijjit avatar Aug 03 '18 20:08 cwadrupldijjit

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.

cwadrupldijjit avatar Aug 03 '18 20:08 cwadrupldijjit

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.

renestalder avatar Jun 27 '19 07:06 renestalder

I haven't touched the code I was writing for months, so I am not sure what the workarounds could be.

cwadrupldijjit avatar Jul 01 '19 20:07 cwadrupldijjit

@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.

jrummell avatar Mar 09 '20 13:03 jrummell