我创建了Angular 2 nativescript项目,在添加了android平台后,我在一个连接的nexus 6p中使用android版本7.1.1运行该项目,当app部署到设备时,我收到了这个错误:
An uncaught Exception occurred on "main" thread.
java.lang.RuntimeException: Unable to create application com.tns.NativeScriptApplication: com.tns.NativeScriptException: Application entry point file not found. Please specify the file in package.json otherwise make sure the file index.js or bootstrap.js exists.\nIf using typescript make sure your entry point file is transpiled to javascript.
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5406)
at android.app.ActivityThread.-wrap2(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1545)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: com.tns.NativeScriptException: Application entry point file not found. Please specify the file in package.json otherwise make sure the file index.js or bootstrap.js exists.\nIf using typescript make sure your entry point file is transpiled to javascript.
at com.tns.Module.bootstrapApp(Module.java:337)
at com.tns.Runtime.run(Runtime.java:508)
at com.tns.NativeScriptApplication.onCreate(NativeScriptApplication.java:17)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1024)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5403)
... 8 more
Caused by: com.tns.NativeScriptException: Failed to find module: "./", relative to: app//
at com.tns.Module.resolvePathHelper(Module.java:159)
at com.tns.Module.bootstrapApp(Module.java:335)
... 12 more
任何想法如何解决这个错误?
更新
我使用tns create name --ng
创建项目,然后使用tns run android
命令运行它。
package.js
文件:
{
"description": "NativeScript Application",
"license": "SEE LICENSE IN <your-license-filename>",
"readme": "NativeScript Application",
"repository": "<fill-your-repository-here>",
"nativescript": {
"id": "org.nativescript.Bazim",
"tns-android": {
"version": "2.4.1"
}
},
"dependencies": {
"@angular/common": "2.2.1",
"@angular/compiler": "2.2.1",
"@angular/core": "2.2.1",
"@angular/forms": "2.2.1",
"@angular/http": "2.2.1",
"@angular/platform-browser": "2.2.1",
"@angular/platform-browser-dynamic": "2.2.1",
"@angular/router": "3.2.1",
"nativescript-angular": "1.2.0",
"nativescript-theme-core": "^0.2.1",
"reflect-metadata": "~0.1.8",
"rxjs": "5.0.0-beta.12",
"tns-core-modules": "2.4.3",
"typescript": "~2.0.10",
},
"devDependencies": {
"babel-traverse": "6.21.0",
"babel-types": "6.21.0",
"babylon": "6.14.1",
"lazy": "1.0.11",
"nativescript-dev-android-snapshot": "^0.*.*",
"nativescript-dev-typescript": "^0.3.2",
"typescript": "~2.0.10",
"zone.js": "~0.6.21"
}
}
答案 0 :(得分:1)
您发布的package.json
文件错误。
app
文件夹中应该有另一个。
看起来应该是这样的:
{
"name": "name",
"main": "app.js", //THIS IT THE ENTRYPOINT
"version": "X.X.X",
"author": {
"name": "Name",
"email": "some@email.com"
},
"description": "some desc!",
"repository": {
"url": "https://github.com/yourrepo"
}
}
验证入口点文件是否存在(它必须是.js
文件而不是打字稿文件),你应该好好去。
答案 1 :(得分:0)
问题来自节点版本,我更新了节点并解决了问题!
答案 2 :(得分:0)
入口点在angular.json中定义
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/output",
"index": "src/index.html",
"main": "src/main.ts",
但是如果我们有任何编译错误,就会发生这样的错误,我在测试和子应用程序中都遇到过,我在tsconfig中将其排除,现在它可以工作了
答案 3 :(得分:0)
就我而言,它与我的NativeScript CLI版本有关。更新了版本,问题已解决。仅供参考,我将angular-cli 7.3.6和NativeScript-cli 5.4.0(已解决问题)更新为NativeScript-cli 5.4.2以解决此问题。任何面临类似问题的人,请尝试更新您的NativeScript CLI版本。