我最近将tns
更新到了6.0.1版本,我读过总是使用webpack
来构建项目。
我在项目中使用了tns migrate
,将本地插件更新为AndroidX(具有Android Studio重构选项),生成了.aar
文件,并在插件演示项目中使用了tns migrate
。之后,当我尝试演示项目时,它确实起作用。我的问题出在我的主项目上:我将新插件添加到我的项目中,删除并添加了Android平台(tns-android
版本6.0.0),但是当我运行tns prepare android
或tns 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
的问题,但是我有tns migrate
的最新版本1.0.1,这是最后一个。这也是我的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"
]
}
答案 0 :(得分:0)
很可能您已经在主要的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"
]
}