【问题标题】:NativeScript - Migrating Project StructureNativeScript - 迁移项目结构
【发布时间】:2019-01-16 21:50:49
【问题描述】:

我想将 Angular 应用程序迁移到 {N} 代码共享结构。我使用this article 开始。您能帮我解决以下问题吗?这似乎是一个错误的配置。

当我执行时:

ng add @nativescript/schematics

我收到以下错误:

success Saved 1 new dependency.
info Direct dependencies
└─ @nativescript/schematics@0.5.0
info All dependencies
└─ @nativescript/schematics@0.5.0
✨  Done in 3.25s.
Installed packages for tooling via yarn.
Two or more projects are using identical roots. Unable to determine project using current working directory. Using default workspace project instead.
    Reading Project Settings
    Project settings:
    {
      "root": "",
      "sourceRoot": "src",
      "mainName": "main",
      "mainPath": "src/main.ts",
      "tsConfig": "src/tsconfig.json",
      "entryModuleClassName": "RootModule",
      "entryModuleImportPath": "./root.module",
      "entryModuleName": "Root",
      "entryModulePath": "/src/root.module.ts",
      "entryComponentClassName": "RootComponent",
      "entryComponentImportPath": "./root.component",
      "entryComponentName": "Root",
      "entryComponentPath": "/src/root.component.ts",
      "indexAppRootTag": "app-root"
    }
    Adding @nativescript/schematics to angular.json
    Adding {N} files
    Adding App_Resources
    Adding NativeScript specific exclusions to .gitignore
    Adding NativeScript run scripts to package.json
    Adding NativeScript Project ID to package.json
    Excluding NativeScript files from web tsconfig
    Adding Sample Shared Component
Two or more projects are using identical roots. Unable to determine project using current working directory. Using default workspace project instead.
Two or more projects are using identical roots. Unable to determine project using current working directory. Using default workspace project instead.
Specified module does not exist

我的 @angular 包是 7.1.1

我使用 yarn 作为包管理器。

这是我的 angular.json:

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "my-ns-project": {
      "root": "",
      "sourceRoot": "src",
      "projectType": "application",
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist",
            "index": "src/index.html",
            "main": "src/main.ts",
            "tsConfig": "src/tsconfig.json",
            "polyfills": "src/polyfills.ts",
            "assets": [
              // assets
            ],
            "styles": [
              // styles
            ],
            "scripts": [
              // scripts
            ]
          },
          "configurations": {
            "hmr": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.hmr.ts"
                }
              ]
            },
            "production": {
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ]
            }
          }
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "my-ns-project:build"
          },
          "configurations": {
            "hmr": {
              "browserTarget": "my-ns-project:build:hmr"
            },
            "production": {
              "browserTarget": "my-ns-project:build:production"
            }
          }
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "my-ns-project:build"
          }
        },
        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "tsConfig": "src/tsconfig.json",
            "main": "src/test.ts",
            "karmaConfig": "./karma.conf.js",
            "polyfills": "src/polyfills.ts",
            "styles": [
              // styles
            ],
            "scripts": [
              // scripts
            ],
            "assets": [
              // assets
            ]
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": [
              "src/tsconfig.json"
            ],
            "exclude": []
          }
        }
      }
    },
    "my-ns-project-e2e": {
      "root": "",
      "sourceRoot": "",
      "projectType": "application",
      "architect": {
        "e2e": {
          "builder": "@angular-devkit/build-angular:protractor",
          "options": {
            "protractorConfig": "./protractor.conf.js",
            "devServerTarget": "my-ns-project:serve"
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": [
              "e2e/tsconfig.json"
            ],
            "exclude": []
          }
        }
      }
    }
  },
  "defaultProject": "my-ns-project",
  "cli": { "defaultCollection": "@nativescript/schematics" },
  "schematics": {
    "@schematics/angular:component": {
      "prefix": "app",
      "styleext": "css"
    },
    "@schematics/angular:directive": {
      "prefix": "app"
    }
  }
}

非常感谢任何帮助!

【问题讨论】:

    标签: nativescript angular2-nativescript nativescript-angular


    【解决方案1】:

    需要按照以下步骤进行

    1. 使用 -ng new my-app 创建一个新的 Angular 应用程序
    2. 导航到我的应用文件夹
    3. 执行命令 - ng add @nativescript/schematics
    4. 最后执行 tns run android --bundle - 这将在模拟器中生成一个自动生成的页面。

    我发现项目设置存在一些差异。

    【讨论】:

    • 您好,感谢您的回复。是的,它适用于使用“ng new”创建的全新应用程序。但是我在现有项目中遇到了这个问题,但无法弄清楚。可能是我的项目模块结构?
    猜你喜欢
    • 2011-06-26
    • 1970-01-01
    • 1970-01-01
    • 2013-04-30
    • 2020-03-07
    • 1970-01-01
    • 2022-06-21
    • 2019-12-25
    • 2014-09-07
    相关资源
    最近更新 更多