问题描述
我有一个使用Angular 8.2.0和NS 6.4.1制作的NativeScript应用程序。我的项目中包含此插件(Fiddle)nativescript-ui-sidedrawer,它运行正常,可以编译该项目。
我在这里遵循了以下指示:https://github.com/ProgressNS/nativescript-ui-feedback将项目更新为Angular 9。
运行此命令时出现错误:tns build android --env.aot
tns build android --env.aot
Preparing project...
Hash: 3428173c1802ae5194b7
Version: webpack 4.27.1
Time: 6666ms
Built at: 17/09/2020 14:38:16
3 assets
Entrypoint bundle = runtime.js vendor.js bundle.js
[../$$_lazy_route_resource lazy recursive] ../$$_lazy_route_resource lazy namespace object 160 bytes {bundle} [built]
[./app.css] 3.15 KiB {bundle} [built]
[./app/app-routing.module.ts] 1.31 KiB {bundle} [built]
[./app/app.component.ts] 1.52 KiB {bundle} [built]
[./app/app.module.ts] 1.72 KiB {bundle} [built]
[./app/home/home-routing.module.ts] 1.22 KiB {bundle} [built]
[./app/home/home.component.ts] 1.82 KiB {bundle} [built]
[./app/home/home.module.ts] 1.78 KiB {bundle} [built]
[./app/home/side-drawer/side-drawer.component.ts] 2.43 KiB {bundle} [built]
[./app/home/side-drawer/side-drawer.service.ts] 1.75 KiB {bundle} [built]
[./main.ts] 1.38 KiB {bundle} [built]
[./package.json] 100 bytes {bundle} [optional] [built]
+ 612 hidden modules
ERROR in ../node_modules/nativescript-ui-sidedrawer/__ivy_ngcc__/angular/side-drawer-directives.js
Module not found: Error: Can't resolve './..' in '/Users/aubrey/Documents/GitHub/Angular9SideDrawer/node_modules/nativescript-ui-sidedrawer/__ivy_ngcc__/angular'
@ ../node_modules/nativescript-ui-sidedrawer/__ivy_ngcc__/angular/side-drawer-directives.js 3:10-25 6:23-38
@ ./app/app.module.ts
@ ./main.ts
Executing webpack Failed with exit code 2.
我尝试卸载并重新安装node_modules,但没有帮助。
这是我的源代码以重现该错误: https://github.com/NativeScript/nativescript-angular/wiki/Updating-and-developing-for-@nativescript-angular-v9-with-Ivy-or-without
package.json
{
"nativescript": {
"id": "org.nativescript.Angular9SideDrawer","tns-android": {
"version": "6.5.0"
},"tns-ios": {
"version": "6.5.0"
}
},"description": "NativeScript Application","license": "SEE LICENSE IN <your-license-filename>","repository": "<fill-your-repository-here>","dependencies": {
"@angular/animations": "~9.1.12","@angular/common": "~9.1.12","@angular/compiler": "~9.1.12","@angular/core": "~9.1.12","@angular/forms": "~9.1.12","@angular/platform-browser": "~9.1.12","@angular/platform-browser-dynamic": "~9.1.12","@angular/router": "~9.1.12","@nativescript/angular": "^9.0.0","@nativescript/core": "^6.5.18","@nativescript/theme": "~2.3.0","nativescript-ui-sidedrawer": "^8.0.1","reflect-Metadata": "~0.1.12","rxjs": "^6.5.5","tns-core-modules": "~6.5.0","tslib": "^1.10.0","zone.js": "~0.10.3"
},"devDependencies": {
"@angular-devkit/schematics": "^10.1.2","@angular/compiler-cli": "^9.1.12","@ngtools/webpack": "^9.1.12","nativescript-dev-webpack": "~1.5.0","typescript": "~3.8.3"
},"gitHead": "20a65d338ae8f8911087ab6615b89363f864b07b","readme": "NativeScript Application","scripts": {
"ngcc": "ngcc --properties es2015 module main --first-only","postinstall": "npm run ngcc"
}
}
解决方法
尝试更新您的nativescript-ui-sidedrawer
软件包,有一个新版本,对我来说您的版本似乎没有正确的配置或无法建立AOT的源代码
确保您的 tsconfig.json
包含
"skipLibCheck": true
如果您正在生成一个新项目但在更新过程中未添加,则它似乎是默认进入的。添加它为我解决了与侧抽屉相关的所有问题,现在我可以毫无问题地编译应用程序。
以下是我的 tsconfig 文件的示例:
{
"compilerOptions": {
"module": "esnext","target": "es2017","moduleResolution": "node","experimentalDecorators": true,"emitDecoratorMetadata": true,"noEmitHelpers": true,"noEmitOnError": true,"skipLibCheck": true,"resolveJsonModule": true,"esModuleInterop": true,"lib": [
"es2017","dom"
],"baseUrl": ".","paths": {
"~/*": [
"src/*"
]
}
},"exclude": [
"node_modules","platforms"
]
}