首页 > 解决方案 > nativescript 6.0.1 无法运行/准备 android 应用程序

问题描述

我最近更新了tns到版本 6.0.1,我读过它总是用于webpack构建项目。

tns migrate在我的项目中使用,将我的本地插件更新为 AndroidX(使用 Android Studio 重构选项),生成我的.aar文件并tns migrate在我的插件演示项目中使用。之后,当我尝试演示项目时,它确实有效。我的问题出在我的主项目上:我将新插件添加到我的项目中,删除并添加了 android 平台(tns-android版本 6.0.0),但是当我运行tns prepare androidtns run android我收到有关我的插件的错误时:

ERROR in /workspace/workspace-nativescript/nativescript-my-plugin/src/my-plugin.ts
Module build failed (from ../node_modules/@ngtools/webpack/src/index.js):
Error: /workspace/workspace-nativescript/nativescript-my-plugin/src/my-plugin.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.
    at NativeScriptAngularCompilerPlugin.getCompiledFile (/workspace/workspace-nativescript/my-project/node_modules/@ngtools/webpack/src/angular_compiler_plugin.js:844:23)
    at NativeScriptAngularCompilerPlugin.getCompiledFile (/workspace/workspace-nativescript/my-project/node_modules/nativescript-dev-webpack/plugins/NativeScriptAngularCompilerPlugin.js:28:26)
    at plugin.done.then (/workspace/workspace-nativescript/my-project/node_modules/@ngtools/webpack/src/loader.js:41:31)
    at process._tickCallback (internal/process/next_tick.js:68:7)

我之前正在阅读关于 的类似问题nativescript-dev-webpack,但我有 1.0.1 版本,tns migrate这是最后一个版本。这也是我的tnsconfig.json文件(我也有一个nsconfig.json文件,但它是空的):

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

标签: webpacknativescriptnativescript-angularnativescript-plugin

解决方案


很可能你已经在你的主要 Angular 应用程序中链接了一个 TypeScript 插件(而不是从 tgz 安装它)。

我想您的插件已经从官方插件种子创建,这就是正确配置演示应用程序的原因,或者您正在运行 TypeScript 演示,而不是 Angular 演示。

当你想在你的 Angular 应用程序中链接一个插件时,你必须包含它的 TypeScript 文件(据我所知,这是AngularCompilerPlugin. 如果您从插件种子 ( tns plugin create) 开始,这已经在您的演示应用程序中进行了配置。

换句话说,tsconfig.json在您的主应用程序 ( /workspace/workspace-nativescript/my-project/tsconfig.json) 中打开并将其内容替换为:

{
    "compilerOptions": {
        "module": "commonjs",
        "target": "es5",
        "experimentalDecorators": true,
        "emitDecoratorMetadata": true,
        "noEmitHelpers": true,
        "noEmitOnError": true,
        "lib": [
            "es6",
            "dom",
            "es2015.iterable"
        ],
        "baseUrl": ".",
        "paths": {
            "~/*": [
                "app/*"
            ],
            "*": [
                "./node_modules/tns-core-modules/*",
                "./node_modules/*"
            ]
        }
    },
    "include": [
        "../nativescript-my-plugin/src",
        "**/*"
    ],
    "exclude": [
        "../nativescript-my-plugin/src/node_modules",
        "node_modules",
        "platforms"
    ]
}

推荐阅读