dashman
dashman

Reputation: 3018

Creating a NS 2.5 project with typescript

I'm trying to create a new 2.5 project with typescript.

tns info says 2.5.3 for NS and 2.5.2 for tns-core-modules.

tns create test --template tsc

When I compile, I get the following error:

`

Executing before-prepare hook from C:\Users\pc\nativescript\sd4\hooks\before-prepare\nativescript-dev-android-snapshot.js Executing before-prepare hook from C:\Users\pc\nativescript\sd4\hooks\before-prepare\nativescript-dev-typescript.js Found peer TypeScript 2.2.2 app/app.ts(8,22): error TS2307: Cannot find module 'application'.

app/bundle-config.ts(1,11): error TS2304: Cannot find name 'global'.

app/bundle-config.ts(3,5): error TS2304: Cannot find name 'require'.

app/bundle-config.ts(6,5): error TS2304: Cannot find name 'global'. app/bundle-config.ts(6,46): error TS2304: Cannot find name 'require'.

app/main-page.ts(8,22): error TS2307: Cannot find module 'ui/page'.

app/main-view-model.ts(23,18): error TS2339: Property 'notifyPropertyChange' does not exist on type 'HelloWorldModel'.

`

Upvotes: 1

Views: 109

Answers (1)

Nick Iliev
Nick Iliev

Reputation: 9670

Here are the steps to create a project with the old template and using NativeScript 2.5.x

tns create test --template [email protected]
cd test
rm -rf hooks
rm -rf platforms
rm -rf node_modules
tns platform add [email protected]
tns plugin remove tns-core-modules
tns plugin add [email protected]
tns build android

This will build you project with the tns-core-modules 2.5.2 and android runtime 2.5.0 and in the end your package.json will look like this

{
  "description": "NativeScript Application",
  "license": "SEE LICENSE IN <your-license-filename>",
  "readme": "NativeScript Application",
  "repository": "<fill-your-repository-here>",
  "nativescript": {
    "id": "org.nativescript.myAppMod25",
    "tns-android": {
      "version": "2.5.0"
    }
  },
  "dependencies": {
    "nativescript-theme-core": "~1.0.2",
    "tns-core-modules": "2.5.2"
  },
  "devDependencies": {
    "babel-traverse": "6.4.5",
    "babel-types": "6.4.5",
    "babylon": "6.4.5",
    "lazy": "1.0.11",
    "nativescript-dev-android-snapshot": "^0.*.*",
    "nativescript-dev-typescript": "~0.3.5",
    "typescript": "~2.1.0"
  }
}

Keep in mind that the first step will create for your tsconfig.json and references.d.ts with the content needed for NativeScript 2.5.x. You can use this application as a reference.

Upvotes: 1

Related Questions