Nativescript: Compile errors when using typescript and tns-platform-declarations

Created on 26 Oct 2016  路  17Comments  路  Source: NativeScript/NativeScript

I want to make some native API references in my typescript code. I followed the instructions in this stackoverflow answer and although the app builds and the autocomplete is working in VSCode. I get the compile time errors shown below.

Which platform(s) does your issue occur on?

iOS

Please provide the following version numbers that your issue occurs with:

  • CLI:2.3.0
  • Cross-platform modules:
    "tns-core-modules": "^2.4.0-2016-10-19-4474"
  • Runtime(s):
    "tns-android": {
    "version": "2.3.0"
    },
    "tns-ios": {
    "version": "2.3.0"
    }

    Errors

tns run ios --emulator
Executing before-prepare hook from ..../hooks/before-prepare/nativescript-dev-typescript.js
Found peer TypeScript 2.0.3
node_modules/tns-platform-declarations/ios/objc-i386/objc!CoreAudio.d.ts(7,13): error TS2403: Subsequent variable declarations must have the same type.  Variable 'AudioBuffer' must be of type '{ new (): AudioBuffer; prototype: AudioBuffer; }', but here has type 'StructType<AudioBuffer>'.

node_modules/tns-platform-declarations/ios/objc-i386/objc!UIKit.d.ts(4954,15): error TS2300: Duplicate identifier 'UIEvent'.

node_modules/tns-platform-declarations/ios/objc-i386/objc!UIKit.d.ts(4954,15): error TS2417: Class static side 'typeof UIEvent' incorrectly extends base class static side 'typeof NSObject'.
  Types of property 'alloc' are incompatible.
    Type '() => UIEvent' is not assignable to type '() => NSObject'.
      Type 'UIEvent' is not assignable to type 'NSObject'.
        Property 'accessibilityActivationPoint' is missing in type 'UIEvent'.

node_modules/typescript/lib/lib.d.ts(15879,11): error TS2300: Duplicate identifier 'UIEvent'.

node_modules/typescript/lib/lib.d.ts(15885,13): error TS2300: Duplicate identifier 'UIEvent'.

Most helpful comment

Hi @devna13,
I tested installation of tns-platform-declarations on my side, however was unable to reproduce this behavior.
Could you change typescript version to 2.0.10 in your project package.json file, remove node_modules, platforms and hooks folder, then try to rebuild your project with tns run <platform_name>;

All 17 comments

Hi @ahalls,
Thank you for reporting this problem.
To avoid the above-given error you should do one more step after you follow the described steps from the StackOverflow question. You should also add the

"include": [
        "typings-i386/*",
        "Interop.d.ts"
    ]

in your tsconfig.json file. You could also review below given summarized description, how to install tns-platform-declarations.

1.install the definition files npm i tns-platform-declarations@next

  1. open references.d.ts in your main app directory and add the following
/// <reference path="./node_modules/tns-core-modules/tns-core-modules.es2016.d.ts" />

/// <reference path="./node_modules/tns-platform-declarations/ios.d.ts" />
/// <reference path="./node_modules/tns-platform-declarations/android.d.ts" />

3, open tsconfig.json in your app and add the support for ES2016 and the missing includes.

{
    "compilerOptions": {
        "module": "commonjs",
        "target": "es5",
        "experimentalDecorators": true,
        "lib": [
            "es2016"
        ]
    },
    "include": [
          "typings-i386/*",
          "Interop.d.ts"
        ]

}

Hope this helps.

Many thanks!

Worked for me also! 馃憤

VS Code all of a sudden can't find modules, but compiles.

@tsonevn I get this error when running $tsc, any idea what I'm doing wrong?

error TS18003: No inputs were found in config file '/Users/me/Workspaces/Git/test/tsconfig.json'. Specified 'include' paths were '["typings-i386/*","Interop.d.ts"]' and 'exclude' paths were '["node_modules","platforms","**/*.aot.ts"]'.

{
    "compilerOptions": {
        "experimentalDecorators": true,
        "noEmitOnError": true,
        "noEmitHelpers": true,
        "sourceMap": true,
        "target": "es5",
        "module": "commonjs",
        "declaration": false,
        "noImplicitAny": false,
        "noImplicitUseStrict": true,
        "emitDecoratorMetadata": true,
        "pretty": true,
        "lib": [
            "es2016"
        ]
    },
    "include": [
        "typings-i386/*",
        "Interop.d.ts"
    ],
    "exclude": [
        "node_modules",
        "platforms",
        "**/*.aot.ts"
    ]
}
 "dependencies": {
    "@angular/common": "2.3.1",
    "@angular/compiler": "2.3.1",
    "@angular/core": "2.3.1",
    "@angular/forms": "2.3.1",
    "@angular/http": "2.3.1",
    "@angular/platform-browser": "2.3.1",
    "@angular/platform-browser-dynamic": "2.3.1",
    "@angular/router": "3.3.1",
    "clone": "2.1.0",
    "email-validator": "1.0.7",
    "moment": "2.17.1",
    "nativescript-angular": "1.3.0",
    "nativescript-appavailability": "^1.2.0",
    "nativescript-appversion": "1.3.2",
    "nativescript-clipboard": "1.1.5",
    "nativescript-directions": "1.0.4",
    "nativescript-fancyalert": "^1.1.2",
    "nativescript-iqkeyboardmanager": "1.0.1",
    "nativescript-local-notifications": "1.2.1",
    "nativescript-phone": "1.2.3",
    "nativescript-pulltorefresh": "1.1.9",
    "nativescript-timedatepicker": "1.1.0",
    "reflect-metadata": "0.1.9",
    "rxjs": "5.0.3",
    "tns-core-modules": "^2.6.0-2017-01-10-5317"
  },
  "devDependencies": {
    "@angular/compiler-cli": "2.3.1",
    "@ngtools/webpack": "1.2.1",
    "babel-traverse": "6.21.0",
    "babel-types": "6.21.0",
    "babylon": "6.14.1",
    "copy-webpack-plugin": "^4.0.1",
    "css-loader": "~0.26.0",
    "extract-text-webpack-plugin": "~2.0.0-beta.4",
    "filewalker": "0.1.3",
    "gulp": "^3.9.1",
    "gulp-clean": "^0.3.2",
    "gulp-replace": "^0.5.4",
    "lazy": "1.0.11",
    "nativescript-dev-sass": "0.4.1",
    "nativescript-dev-typescript": "^0.3.2",
    "nativescript-dev-webpack": "0.3.0",
    "raw-loader": "~0.5.1",
    "resolve-url-loader": "~1.6.0",
    "tns-platform-declarations": "^2.4.4",
    "typescript": "2.1.4",
    "webpack": "~2.1.0-beta.27",
    "webpack-sources": "~0.1.3",
    "zone.js": "0.7.4"
  }

Hi @devna13,
I tested installation of tns-platform-declarations on my side, however was unable to reproduce this behavior.
Could you change typescript version to 2.0.10 in your project package.json file, remove node_modules, platforms and hooks folder, then try to rebuild your project with tns run <platform_name>;

@x00 same for me. Why can't find modules!?

My issue was misnamed app in app.gradle

@x00 Can you explain more about your case? I'm actually working only for iOS, so no app.gradle file

I figured adding

"include": [
          "typings-i386/*",
          "Interop.d.ts"
        ]

caused "can't find module" errors in VSCode. Don't know why

Did anyone ever resolve this as I am having the same issues?

error TS18003: No inputs were found in config file '<Project-Path>/tsconfig.json'. Specified 'include' paths were '["typings-i386/*","Interop.d.ts"]' and 'exclude' paths were '["node_modules","platforms","**/*.aot.ts"]'.

Hi @tonyhogben,
Could you provide some more info about your environment(CLI, modules version) and info about the template which you are using, whether it is NativeScript Angular 2 one or pure NativeScript?

It would also help if you could share your tsconfig.jsonfile and references.d.ts files.
In the meantime, make sure that you made all needed changes described in the ReadMe here.

@tsonevn, thanks for picking this up.

I am using pure Nativescript based off a recent copy of the base (tns-template-hello-world-ts) TypeScript template.

  • NativeScript v3.0.1
  • Core Modules v3.0.0
  • Typescript v2.2.1

tsconfig.json:

{
    "compilerOptions": {
        "module": "commonjs",
        "target": "es5",
        "experimentalDecorators": true,
        "emitDecoratorMetadata": true,
        "noEmitHelpers": true,
        "noEmitOnError": true,
        "lib": [
            "es6",
            "dom"
        ],
        "baseUrl": ".",
        "paths": {
            "*": [
                "./node_modules/tns-core-modules/*",
                "./node_modules/*"
            ]
        }
    },
    "exclude": [
        "node_modules",
        "platforms",
        "**/*.aot.ts"
    ]
}

references.d.ts:

/// <reference path="./node_modules/tns-platform-declarations/android.d.ts" />
/// <reference path="./node_modules/tns-platform-declarations/ios.d.ts" />

@tonyhogben try updating your NativeScript to the latest version (at this very moment 3.0.3).

Here you can find a sample project using the latest modules, runtime and CLI 3.0.3 along with tns-platform-declarations and the needed references.d.ts and it works as expected on my side.

@tsonevn, that appears to have cracked it. Thank you for your assistance!

I am getting tns-core-modules.es2016.d.ts' not found, what should I do for get tns-core-modules.es2016.d.ts ?

1 /// <reference path="./node_modules/tns-core-modules/tns-core-modules.es2016.d.ts" />
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

references.d.ts(1,1): error TS6053: File '/home/indianic/data/nativescript/ivypay-app/node_modules/tns-core-modules/tns-core-modules.es2016.d.ts' not found.

Hi @vinitsolanki,
Could you confirm that you have followed the updated instructions in the ReamMe file in NPM?
Also, try to remove platforms and node_modules folders and rebuild the project.
If the problem still persists, please send us your tsconfig.json and reference.d.ts files.

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mspusta78 picture mspusta78  路  59Comments

NickIliev picture NickIliev  路  58Comments

lscown picture lscown  路  58Comments

tjvantoll picture tjvantoll  路  58Comments

valentinstoychev picture valentinstoychev  路  136Comments