Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot find type definition file #20

Open
ravirambles opened this issue Apr 21, 2018 · 10 comments
Open

Cannot find type definition file #20

ravirambles opened this issue Apr 21, 2018 · 10 comments

Comments

@ravirambles
Copy link

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?

@ktsn
Copy link
Owner

ktsn commented Apr 22, 2018

Can you provide a reproduction?

@ravirambles
Copy link
Author

sorry for the vague description, create a sample repo

https://github.com/ravirambles/vuetypeissue

@ravirambles
Copy link
Author

If I remove the types

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

from the tsconfig.json it is working as expected.

@ghost
Copy link

ghost commented May 6, 2018

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

@cwadrupldijjit
Copy link

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
Copy link

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
Copy link

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.

@renestalder
Copy link

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.

@cwadrupldijjit
Copy link

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

@jrummell
Copy link

jrummell commented Mar 9, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants