Skip to content

Ionic V2 + TypeScript cordova is not defined #6836

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

Closed
tryadelion opened this issue Jun 10, 2016 · 6 comments
Closed

Ionic V2 + TypeScript cordova is not defined #6836

tryadelion opened this issue Jun 10, 2016 · 6 comments

Comments

@tryadelion
Copy link

tryadelion commented Jun 10, 2016

Using ionic v2 with typescript, i can't use any cordova module. it throws up "cordova is not defined" both on devices and on the browser, and there is a complete lack of documentation on how do to so correctly, so i'm pretty much stuck.

Steps to reproduce:

  1. install ionic v2
  2. install cordova plugin ( InAppBrowser for example) through CLI
  3. install TSD as some comments say on 'The Internet'® , run it, see how ts definition files are generated automatically. neat.
    3.1 try to run it as some tutorials show it. find you no longer can import "ionic/ionic". find you no longer can import "ionic-framework/ionic". find you now have to import "ionic-angular". keep calm.
  4. ionic serve. didn't work. there is no exported module called cordova.
  5. try to import {cordova} from "cordova"; there is no exported module called cordova.
  6. wait for a miracle and that "cordova.InAppBrowser.open" will magically work at some point.

IONIC INFO

Cordova CLI: 6.2.0
Gulp version: CLI version 3.9.1
Gulp local: Local version 3.9.1
Ionic Framework Version: 2.0.0-beta.8
Ionic CLI Version: 2.0.0-beta.30
Ionic App Lib Version: 2.0.0-beta.16
OS:
Node Version: v6.2.1

@Ionitron Ionitron added the v2 label Jun 10, 2016
@tryadelion tryadelion changed the title Ionic V2 + TypeScript cordova ordova is not defined Ionic V2 + TypeScript cordova cordova is not defined Jun 10, 2016
@tryadelion tryadelion changed the title Ionic V2 + TypeScript cordova cordova is not defined Ionic V2 + TypeScript cordova is not defined Jun 10, 2016
@iignatov
Copy link
Contributor

TSD is deprecated, you should install typings instead.

Try if running the following commands will fix the issue:

npm install typings --global
typings install dt~cordova --global --save

Also I think that you should use InAppBrowser.open() instead of cordova.InAppBrowser.open().

If the details above don't help, could you post some of the code that causes the problem?

On a side note, I would also recommend you to use Node v4/5 since Node v6 is not supported yet.

@tryadelion
Copy link
Author

well that did work indeed, thank you very much, it should be added to the official documentation.

@jgw96
Copy link
Contributor

jgw96 commented Jun 10, 2016

Hello all! I would like to add that Ionic Native now supports a wide range of plugins and gives you full typescript support, including intellisense, out of the box without having to install any typings.

@iignatov
Copy link
Contributor

@jgw96, thanks for the tip! Here's a sample snippet for reference. I haven't tested it but it should work:

import { InAppBrowser } from 'ionic-native';
// ...
    InAppBrowser.open(/* ... */);
// ...

@matheo
Copy link
Contributor

matheo commented Jun 11, 2016

@iignatov I updated an Ionic beta.6 project to beta.8 and now I'm using typings.

Installing new definitions creates the file typings/index.d.ts and all is working fine, I've added it to the repository too, but i'm having a minor issue with Atom IDE, it says:

[TS] [Error] The file "typings/main.d.ts" is not included in the TypeScript compilation context. If this is not intended, please check the "files" or "filesGlob" section of your tsconfig.json file.

My tsconfig.json is basically the same as a clean install of beta.8:

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true
  },
  "filesGlob": [
    "**/*.ts",
    "!node_modules/**/*"
  ],
  "exclude": [
    "node_modules",
    "typings/main",
    "typings/main.d.ts"
  ],
  "compileOnSave": false,
  "atom": {
    "rewriteTsconfig": false
  }
}

My question is: Do I need to copy the contents of index.d.ts into main.d.ts and delete it, because without it I had no errors!
Thanks in advance

@iignatov
Copy link
Contributor

@matheo I'm not quite sure because I don't use Atom (but VS Code instead) and I still haven't updated to typings 1.x which introduces index.d.ts. I would recommend you to do a global search for main.d.ts in the project and remove all occurrences (and probably the same for typings/main). Also check the typings folder for obsolete files, e.g. main.d.ts.

Do I need to copy the contents of index.d.ts into main.d.ts and delete it, because without it I had no errors!

I wouldn't do this because this might cause problems with typings and also sounds like a hack.

If you didn't manage to find a solution I would recommend you to open an issue in the TypeStrong/atom-typescript repository because it might be a bug or something that's not supported yet.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Sep 8, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants