将项目从角度2转换为角度5后,打字似乎完全搞砸了 [英] Typings seems utterly messed up after converting project from angular 2 to angular 5

查看:67
本文介绍了将项目从角度2转换为角度5后,打字似乎完全搞砸了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

升级到angular 5后,我在编译项目时遇到问题.项目可能无法编译,可能是因为打字搞砸了.该项目以前使用过打字,但是我尝试使用@types以更现代的方式安装它,但也无法修复.

I am having problems compiling the project after upgrading to angular 5. The project fails to compile probably because typing is messed up. The project previously used typings, but I've tried to install this in the more modern way using @types but it doesn't fix it either.

以下是当前package.json:

The following is the current package.json:

{
    "name": "my-app",
    "version": "1.0.0",
    "author": "geewhizbang",
    "description": "Package for my-app",
    "scripts": {
        "start": "concurrently \"npm run tsc:w\" \"npm run lite\" ",
        "tsc": "tsc",
        "tsc:w": "tsc -w",
        "lite": "lite-server",
        "build": "npm run clean && tsc",
        "test": "tsc && concurrently \"tsc -w\" \"karma start karma.conf.js\"",
        "posttest": "node_modules/.bin/remap-istanbul -i coverage/coverage-final.json -o coverage -t html",
        "coverage": "http-server -c-1 -o -p 9875 ./coverage"
    },
    "license": "ISC",
    "dependencies": {
        "@angular/animations": "^5.2.10",
        "@angular/common": "^5.2.10",
        "@angular/compiler": "^5.2.10",
        "@angular/compiler-cli": "^5.2.10",
        "@angular/core": "^5.2.10",
        "@angular/forms": "^5.2.10",
        "@angular/http": "^5.2.10",
        "@angular/platform-browser": "^5.2.10",
        "@angular/platform-browser-dynamic": "^5.2.10",
        "@angular/platform-server": "^5.2.10",
        "@angular/router": "^5.2.10",
        "@angular/upgrade": "2.3.0-rc.0",
        "bootstrap": "^3.3.6",
        "core-js": "^2.4.1",
        "es6-shim": "^0.35.0",
        "font-awesome": "^4.7.0",
        "karma-coverage": "^1.1.1",
        "reflect-metadata": "^0.1.8",
        "remap-istanbul": "^0.8.4",
        "rxjs": "5.0.0-rc.4",
        "systemjs": "0.19.40",
        "zone.js": "^0.7.2"
    },
    "devDependencies": {
        "@types/angular": "^1.6.43",
        "@types/angular-mocks": "^1.5.11",
        "@types/angular-route": "^1.3.5",
        "@types/angularlocalstorage": "^0.1.32",
        "@types/express": "^4.11.1",
        "@types/express-serve-static-core": "^4.11.1",
        "@types/gulp": "^4.0.5",
        "@types/jasmine": "^2.5.36",
        "@types/jquery": "^3.3.1",
        "@types/mime": "^2.0.0",
        "@types/node": "^6.0.106",
        "@types/q": "^1.5.0",
        "@types/serve-static": "^1.13.1",
        "babel-core": "^6.23.1",
        "browserify": "^14.1.0",
        "canonical-path": "0.0.2",
        "compress": "^0.99.0",
        "concurrently": "^3.1.0",
        "del": "^2.2.2",
        "gulp": "^3.9.1",
        "gulp-concat": "^2.6.1",
        "gulp-imagemin": "^3.1.1",
        "gulp-sourcemaps": "^2.4.1",
        "gulp-typescript": "^3.1.5",
        "gulp-uglify": "^2.0.1",
        "http-server": "^0.9.0",
        "jasmine-core": "~2.4.1",
        "karma": "^1.3.0",
        "karma-chrome-launcher": "^2.0.0",
        "karma-cli": "^1.0.1",
        "karma-jasmine": "^1.0.2",
        "karma-jasmine-html-reporter": "^0.2.2",
        "lite-server": "^2.2.2",
        "lodash": "^4.16.4",
        "mangle": "^1.1.3",
        "protractor": "~4.0.14",
        "rimraf": "^2.5.4",
        "systemjs-builder": "^0.16.3",
        "tslint": "^3.15.1",
        "typescript": "^2.8.3",
        "uglifyjs": "^2.4.10"
    },
    "repository": {}
}

上述文件是通过使用npm install从原始文件升级的:

The above file was upgraded from the original by using npm install:

npm install @angular/common@latest @angular/compiler@latest @angular/compiler-cli@latest @angular/core@latest @angular/forms@latest @angular/http@latest @angular/platform-browser@latest @angular/platform-browser-dynamic@latest @angular/platform-server@latest @angular/router@latest @angular/animations@latest typescript@latest --save

但是它现在无法编译,因为类型以某种方式被弄乱了.

But it now fails to compile because types are messed up somehow.

以下是当前的tsconfig.json:

The following is the current tsconfig.json:

{
    "compilerOptions": {
        "target": "es6",
        "module": "system",
        "moduleResolution": "node",
        "sourceMap": false, // make this false for minification
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "removeComments": false,
        "noImplicitAny": false,
        "noStrictGenericChecks": true,
        "outFile": "./app/app.min.js", // uncomment this line for minification
        "typeRoots": [
            "node_modules/@types"
        ]
    },
    "compileOnSave": true,
    "exclude": [
        "node_modules",
        "typings",
        //comment out these two lines for jasmine
        "./app/**/*.spec.ts",
        "./app/*.spec.ts"
    ]
}

我尝试遵循该开发人员在转换为@types时的建议:

I tried to follow what this developer suggested in converting to @types:

https://georgedyrra.com/2017/06/04/从类型迁移到npm-types/

推荐答案

在上述package.json中,我删除了es6-shim和angular升级.我重命名过时的类型文件夹而不是删除它也无济于事. NPM会编译根目录以外的所有内容,显然它并不关心我所想的文件夹名称.

In the above package.json I removed es6-shim and angular upgrade. It also didn't help that I had renamed the obsolete typings folder instead of just deleting it. NPM compiles everything past the root, it apparently doesn't care about folder names like I thought.

这实际上是如何升级的一个很好的例子.使用npm install进行最新操作比我以前尝试进行的所有手动编辑做得更好.

It actually is a good example of how to upgrade. Using npm install to do the latest did a better job than all the manual editing I had done on previous attempts.

这篇关于将项目从角度2转换为角度5后,打字似乎完全搞砸了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆