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 · 9 comments
Open

Cannot find type definition file #20

ravirambles opened this issue Apr 21, 2018 · 9 comments

Comments

@ravirambles
Copy link

@ravirambles ravirambles commented Apr 21, 2018

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

This comment has been minimized.

Copy link
Owner

@ktsn ktsn commented Apr 22, 2018

Can you provide a reproduction?

@ravirambles

This comment has been minimized.

Copy link
Author

@ravirambles ravirambles commented Apr 22, 2018

sorry for the vague description, create a sample repo

https://github.com/ravirambles/vuetypeissue

@ravirambles

This comment has been minimized.

Copy link
Author

@ravirambles ravirambles commented Apr 26, 2018

If I remove the types

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

from the tsconfig.json it is working as expected.

@kilroy05

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link

@cwadrupldijjit cwadrupldijjit commented Aug 3, 2018

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

This comment has been minimized.

Copy link

@cwadrupldijjit cwadrupldijjit commented Aug 3, 2018

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

This comment has been minimized.

Copy link

@cwadrupldijjit cwadrupldijjit commented Aug 3, 2018

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

This comment has been minimized.

Copy link

@renestalder renestalder commented Jun 27, 2019

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

This comment has been minimized.

Copy link

@cwadrupldijjit cwadrupldijjit commented Jul 1, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.