Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
尝试生成我的Angular2应用程序时出错_Angular - Fatal编程技术网

尝试生成我的Angular2应用程序时出错

尝试生成我的Angular2应用程序时出错,angular,Angular,我为几年前制作的Angular2课程开发了一个应用程序。该应用程序在我的本地主机上运行良好,但当我使用ng build创建dist文件夹以便在internet上实时发布时,我会遇到错误。这是我的package.json文件: { "name": "task-card-app", "version": "1.0.0", "description": "udemy.com Angular2 app built on skeleton project", "script

我为几年前制作的Angular2课程开发了一个应用程序。该应用程序在我的本地主机上运行良好,但当我使用ng build创建dist文件夹以便在internet上实时发布时,我会遇到错误。这是我的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
Unable to find any apps in `.angular-cli.json`.
更新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上运行时,我得到了一长串节点模块错误

我在devdependences中添加了@angular/compiler cli,并删除了package-lock.json和node_模块,然后再次运行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
Unable to find any apps in `.angular-cli.json`.
在其他情况下,修补东西的版本并运行npm安装和ng构建会产生:

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)
正如您在下面的package.json文件中所看到的,devdependency不包括“@angular/cli”:“^1.7.4”,但ng build仍然不起作用。如果在下面的评论中提到,“angular.json”是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"
    }
}

angular.json
用于Angular6,而
angular cli.json
用于Angular2-5。因此,当您在旧项目上运行
npm install
命令时,它在更高版本中运行。我会说,试着删除所有的
^
,删除
节点模块
文件夹,然后重新运行
npm安装
。另外,我不相信Angular CLI是几年前的事了,所以从你的
包.json
中提取它,然后按照你当时的方式构建应用程序。或者你将被迫完全升级你的应用程序。安德鲁·洛班(Andrew Lobban):为了记录在案,我的package.json最初没有胡萝卜,但我再次删除了胡萝卜,并尝试了你的建议。ng build仍然生成安装@angular的请求/core@latest.Also,这门课程是几年前制作的,但我最近才开发了这个应用程序。我不知道我是如何在devdependences中使用“@angular/cli”:“^1.7.4”的,但是没有它,应用程序无法运行。我应该补充的是,这个应用程序确实包含一个小部件,它不是建立在最初的课程框架上的。我可能用了CLI。不确定这会有什么影响。