尝试构建我的Angular2应用程序时出现错误

时间:2018-05-30 20:36:41

标签: angular

我为几年前制作的Angular2课程构建了一个应用程序。该应用程序在我的Localhost上工作正常,但当我使用ng build创建一个dist文件夹以便在互联网上发布时,我收到错误。这是我的package.json文件:

{
    "name": "task-card-app",
    "version": "1.0.0",
    "description": "udemy.com Angular2 app built on skeleton project",
    "scripts": {
        "start": "tsc && concurrently \"tsc -w\" \"lite-server\" ",
        "lite": "lite-server",
        "tsc": "tsc",
        "tsc:w": "tsc -w"
    },
    "license": "UNLICENSED",
    "repository": {
        "type": "git",
        "url": ""
    },
    "dependencies": {
        "@angular/common": "^2.1.2",
        "@angular/compiler": "^2.1.2",
        "@angular/core": "^2.1.2",
        "@angular/forms": "^2.1.2",
        "@angular/http": "^2.1.2",
        "@angular/platform-browser": "^2.1.2",
        "@angular/platform-browser-dynamic": "^2.1.2",
        "@angular/router": "3.1.2",
        "@angular/upgrade": "^2.1.2",
        "angular-in-memory-web-api": "0.1.13",
        "bootstrap": "4.0.0-alpha.5",
        "core-js": "2.4.1",
        "font-awesome": "^4.7.0",
        "reflect-metadata": "0.1.8",
        "rxjs": "^5.0.0-beta.12",
        "systemjs": "0.19.40",
        "zone.js": "^0.6.25"
    },
    "devDependencies": {
        "@angular/cli": "^1.7.4",
        "@types/core-js": "0.9.34",
        "@types/node": "6.0.46",
        "concurrently": "3.1.0",
        "lite-server": "2.2.2",
        "typescript": "2.0.6"
    }
}

通过此配置,ng build生成了以下消息:

Your global Angular CLI version (6.0.1) is greater than your local
version (1.7.4). The local Angular CLI version is used.

This version of CLI is only compatible with angular version 2.3.1 or better. Please upgrade your angular version, e.g. by running:
npm install @angular/core@latest

更新angular core会产生许多对等依赖项问题,并出现以下消息:

Versions of @angular/compiler-cli and typescript could not be determined.
The most common reason for this is a broken npm install.
    Please make sure your package.json contains both @angular/compiler-cli and typescript in
    devDependencies, then delete node_modules and package-lock.json (if you have one) and
    run npm install again.

。 。 。并尝试再次在localhost上运行它我得到了很长的节点模块错误列表。

我将@ angular / compiler-cli添加到devDependencies,并删除了package-lock.json和node_modules,然后再次运行ng build产生了这条消息:

Unable to find any apps in `.angular-cli.json`.

在其他情况下,修改事物的版本并运行npm install和ng build:

Local workspace file ('angular.json') could not be found.
Error: Local workspace file ('angular.json') could not be found.
    at WorkspaceLoader._getProjectWorkspaceFilePath (C:\Users\cadle\AppData\Roaming\npm\node_modules\@angular\cli\models\workspace-loader.js:37:19)
    at WorkspaceLoader.loadWorkspace (C:\Users\cadle\AppData\Roaming\npm\node_modules\@angular\cli\models\workspace-loader.js:24:21)
    at BuildCommand._loadWorkspaceAndArchitect (C:\Users\cadle\AppData\Roaming\npm\node_modules\@angular\cli\models\architect-command.js:180:32)
    at BuildCommand.<anonymous> (C:\Users\cadle\AppData\Roaming\npm\node_modules\@angular\cli\models\architect-command.js:47:25)
    at Generator.next (<anonymous>)
    at C:\Users\cadle\AppData\Roaming\npm\node_modules\@angular\cli\models\architect-command.js:7:71
    at new Promise (<anonymous>)
    at __awaiter (C:\Users\cadle\AppData\Roaming\npm\node_modules\@angular\cli\models\architect-command.js:3:12)
    at BuildCommand.initialize (C:\Users\cadle\AppData\Roaming\npm\node_modules\@angular\cli\models\architect-command.js:46:16)
    at Object.<anonymous> (C:\Users\cadle\AppData\Roaming\npm\node_modules\@angular\cli\models\command-runner.js:87:23)

我一直在寻找几个小时,并尝试了其他一些事情,但这是它的要点。

我的问题是,如何将我的应用程序构建到dist文件夹中,以便我可以在互联网上托管应用程序?

更新 我在构建上述项目的原始框架项目上运行了npm install,以查明问题是否从一开始就存在,并且运行ng build产生的结果与上面开始的结果相同:

Local workspace file ('angular.json') could not be found.

正如您在下面的package.json文件中所看到的,devDependencies不包括&#34; @ angular / cli&#34;:&#34; ^ 1.7.4&#34;,但ng build仍然不起作用。如果如下面的评论所述,&#39; angular.json&#39;是Angular 6,我不明白为什么需要建立一个旧的Angular 2骨架项目。也许是因为我在全球范围内运行Angular 6。我将考虑全局恢复旧版本,看看是否有所作为。

更新 不。在全球范围内安装旧版本根本没有帮助。

{
    "name": "angular2-skeleton",
    "version": "1.0.0",
    "description": "First Angular2 Skeleton Project",
    "scripts": {
        "start": "tsc && concurrently \"tsc -w\" \"lite-server\" ",
        "lite": "lite-server",
        "tsc": "tsc",
        "tsc:w": "tsc -w"
    },
    "license": "UNLICENSED",
    "repository": {
        "type": "git",
        "url": ""
    },
    "dependencies": {
        "@angular/common": "2.1.2",
        "@angular/compiler": "2.1.2",
        "@angular/core": "2.1.2",
        "@angular/forms": "2.1.2",
        "@angular/http": "2.1.2",
        "@angular/platform-browser": "2.1.2",
        "@angular/platform-browser-dynamic": "2.1.2",
        "@angular/router": "3.1.2",
        "angular-in-memory-web-api": "0.1.13",
        "bootstrap": "4.0.0-alpha.5",
        "core-js": "2.4.1",
        "reflect-metadata": "0.1.8",
        "rxjs": "5.0.0-beta.12",
        "systemjs": "0.19.40",
        "zone.js": "0.6.26"
    },
    "devDependencies": {
        "@types/core-js": "0.9.34",
        "@types/node": "6.0.46",
        "concurrently": "3.1.0",
        "lite-server": "2.2.2",
        "typescript": "2.0.6"
    }
}

0 个答案:

没有答案