【问题标题】:Creating a NS 2.5 project with typescript使用 typescript 创建 NS 2.5 项目
【发布时间】:2017-10-23 07:36:06
【问题描述】:

我正在尝试使用 typescript 创建一个新的 2.5 项目。

tns info 表示 NS 为 2.5.3,tns-core-modules 为 2.5.2。

tns 创建测试 --template tsc

编译时出现以下错误:

`

从 C:\Users\pc\nativescript\sd4\hooks\before-prepare\nativescript-dev-android-snapshot.js 执行 before-prepare 钩子 从 C:\Users\pc\nativescript\sd4\hooks\before-prepare\nativescript-dev-typescript.js 执行 before-prepare 钩子 找到对等的 TypeScript 2.2.2 app/app.ts(8,22):错误 TS2307:找不到模块“应用程序”。

app/bundle-config.ts(1,11):错误 TS2304:找不到名称“全局”。

app/bundle-config.ts(3,5):错误 TS2304:找不到名称 'require'。

app/bundle-config.ts(6,5):错误 TS2304:找不到名称“全局”。 app/bundle-config.ts(6,46): 错误 TS2304: 找不到名称 'require'。

app/main-page.ts(8,22): 错误 TS2307: 找不到模块 'ui/page'。

app/main-view-model.ts(23,18):错误 TS2339:“HelloWorldModel”类型上不存在属性“notifyPropertyChange”。

`

【问题讨论】:

  • tsc 模板已更新为适用于所有 3.0 位。您需要通过 tns create test --template tns-template-hello-world-ts@2.5 专门指向 2.5 typescript 模板

标签: nativescript


【解决方案1】:

以下是使用旧模板和 NativeScript 2.5.x 创建项目的步骤

tns create test --template tns-template-hello-world-ts@2.5.0
cd test
rm -rf hooks
rm -rf platforms
rm -rf node_modules
tns platform add android@2.5.0
tns plugin remove tns-core-modules
tns plugin add tns-core-modules@2.5.2
tns build android

这将使用 tns-core-modules 2.5.2 和 android runtime 2.5.0 构建您的项目,最后您的 package.json 将如下所示

{
  "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"
  }
}

请记住,第一步将为您的 tsconfig.jsonreferences.d.ts 创建 NativeScript 2.5.x 所需的内容。您可以使用this application 作为参考。

【讨论】:

    猜你喜欢
    • 2014-10-03
    • 1970-01-01
    • 2017-04-29
    • 2021-06-13
    • 2020-04-11
    • 1970-01-01
    • 2014-11-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多