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" using @types type definitions #145

Closed
bmayen opened this issue Jul 24, 2016 · 10 comments
Closed

"Cannot find type definition file" using @types type definitions #145

bmayen opened this issue Jul 24, 2016 · 10 comments

Comments

@bmayen
Copy link

bmayen commented Jul 24, 2016

Using typescript@beta. My tsconfig.json has "types": ["jquery"] and I have installed @types/jquery under both node_modules and jspm_packages (as part of my debugging effort). When I build my project I get the following error:
"Cannot find type definition file for 'jquery'. (TS2688)"

I have tried other packages as well, but none are found.

@frankwallis
Copy link
Owner

Thanks for raising this, it is not implemented yet, I need to read up on this feature and figure out how it will work in plugin-typescript.

@fchiumeo
Copy link

I use typescript@beta and works

tsconfig.json

{
    "compilerOptions": {
        "target": "es5",
        "module": "system",
        "moduleResolution": "node",
        "sourceMap": false,
        "inlineSourceMap": false,
        "experimentalDecorators": true,
        "emitDecoratorMetadata": true,
        "types": [ "core-js", "jasmine" ]
    },
    "exclude": [
        "node_modules"
    ]
}

systemjs.config.js

        typescriptOptions: {
                tsconfig: true,
                types: []
            }

@frankwallis @types/ replace typings config,no more typings.json or typings install
The Future of Declaration Files

@bmayen
Copy link
Author

bmayen commented Jul 28, 2016

What version of the plugin and JSPM are you using? And where did you install the types; under jspm_packages or node_modules?

@fchiumeo
Copy link

"systemjs": "0.19.32"
"systemjs-builder": "0.15.23"
"plugin-typescript": "5.0.1"

all installed in node_modules, not using jspm packages

@bmayen
Copy link
Author

bmayen commented Jul 28, 2016

Interesting. I'm on systemjs@0.19.31, but that doesn't seem likely to be the issue.

Latest version of the plugin though. Any chance you could update the plugin to verify if it still works at latest?

If so, the only difference I see is that I'm using JSPM. @guybedford, do you have any insight as to why this might not work using JSPM?

@dballesteros7
Copy link

@fchiumeo Are you sure it is working? I think your types: [] is overriding the first one and nullifying the load of the type declarations.

@frankwallis I took a look into this and the blocking point is that the compiler host in plugin-typescript doesn't provide the files that Typescript is looking for.

Installing to jspm_packages does not seem possible because Typescript search for things like jspm_packages/@types/package_name without the added @version_number.

When using node_modules the problem is that Typescript starts looking for http://localhost:xxx/node_modules/angular/package.json and index.d.ts in the Host files but on the first transpile call the host files only contain the main file.

I wonder if the plugin could do a scan of all files under typeRoots, similar to what Typescript does in:
https://github.com/Microsoft/TypeScript/blob/v2.0.0-beta/src/compiler/program.ts#L1058 and make those files available in the compiler host for when typescript requests them.

I would love to help out with this but my knowledge is so far a couple of hours of debugging and reading the source code so I don't know what's the best way to address it.

@aindlq
Copy link
Contributor

aindlq commented Aug 11, 2016

@dballesteros7 is right, it can't work with current implementation of plugin-typescript. At least it shouldn't....

Actually, most of the time, in tsc one does not need to provide explicit types in tsconfig. There is additional property typeRoots which has some defaults for node_modules/@types

Looks like ts expose speciall method ts.resolveTypeReferenceDirective which one can use to properly resolve @types, maybe it can be used in host's resolveModuleNames function. This method depends on other host functions like getSourceFile, fileExists, etc.

I'm not really familiar with typescript API, but that is what I found looking around.

Also I've found few existing bugs related to type resolution, e.g:
microsoft/TypeScript#9831

For more details see microsoft/TypeScript#9184

@frankwallis
Copy link
Owner

I have implemented some basic support for the types configuration option in 5.0.18. It is now used in the react and angular1 example projects. Also there is some information on the readme: https://github.com/frankwallis/plugin-typescript/blob/master/README.md#types-types-support

Let me know if you find any issues, thanks

@tamird
Copy link
Contributor

tamird commented Aug 23, 2016

This seems to look for the typings in the wrong place:

jspm bundle-sfx app/app build/app.js
     Building the single-file sfx bundle for app/app...

err  Error on fetch for npm:@types/react-dom@0.14.15.js/index.d.ts!github:frankwallis/plugin-typescript@5.0.18/plugin.js at file:///Users/tamird/src/go/src/github.com/cockroachdb/cockroach/ui/jspm_packages/npm/@types/react-dom@0.14.15.js/index.d.ts!file:///Users/tamird/src/go/src/github.com/cockroachdb/cockroach/ui/jspm_packages/github/frankwallis/plugin-typescript@5.0.18/plugin.js
    Loading app/app.tsx
    Error: ENOENT: no such file or directory, open '/Users/tamird/src/go/src/github.com/cockroachdb/cockroach/ui/jspm_packages/npm/@types/react-dom@0.14.15.js/index.d.ts'

Note that .js suffix on the directory name - this suffix is not present on disk.

@frankwallis
Copy link
Owner

I think this is caused by jspm@0.16 and the defaultJsExtensions behaviour. I am not able to recreate in the react example project using jspm@0.17-beta. I have added a patch in 5.0.19 which I hope will fix this.

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

No branches or pull requests

6 participants