放大角度构建错误

Posted

技术标签:

【中文标题】放大角度构建错误【英文标题】:Amplify angular build error 【发布时间】:2019-01-05 18:52:20 【问题描述】:

我在 Angular 项目中使用 Amplify angular。构建时出错。

这里是错误:

错误 node_modules/@ionic/core/dist/types/utils/overlays.d.ts(9,82):错误 TS2344:类型“keyof B”不满足约束“字符串”。 键入'字符串 |号码 |符号'不可分配给类型'字符串'。 类型“数字”不可分配给类型“字符串”。

包.json


    "name": "******",
    "version": "0.0.2",
    "license": "UNLICENSED",
    "config": 
        "host": "*********",
        "cloudfront": "**********"
    ,
    "scripts": 
        "ng": "ng",
        "start": "[ -f src/aws-exports.js ] && mv src/aws-exports.js src/aws-exports.ts || ng serve; ng serve",
        "build": "npm run commit && [ -f src/aws-exports.js ] && mv src/aws-exports.js src/aws-exports.ts || ng build --configuration=production; ng build --configuration=production",
        "commit": "git add -A && git commit -m 'an other commit' && git push",
        "deploy": "aws s3 rm s3://$npm_package_config_host --recursive && aws s3 sync ./dist/browser s3://$npm_package_config_host --cache-control='max-age=2628000, public' && aws cloudfront create-invalidation --distribution-id $npm_package_config_cloudfront --paths '/*'",
        "build:s-s-r": "npm run build:client-and-server-bundles && npm run webpack:server",
        "serve:s-s-r": "node dist/server",
        "build:client-and-server-bundles": "ng build --configuration=production && ng run ******:server",
        "webpack:server": "webpack --config webpack.server.config.js --progress --colors"
    ,
    "private": true,
    "dependencies": 
        "@angular/animations": "^6.1.0",
        "@angular/common": "^6.1.0",
        "@angular/compiler": "^6.1.0",
        "@angular/core": "^6.1.0",
        "@angular/forms": "^6.1.0",
        "@angular/http": "^6.1.0",
        "@angular/platform-browser": "^6.1.0",
        "@angular/platform-browser-dynamic": "^6.1.0",
        "@angular/platform-server": "^6.1.0",
        "@angular/router": "^6.1.0",
        "@nguniversal/common": "^6.0.0",
        "@nguniversal/express-engine": "^6.0.0",
        "@nguniversal/module-map-ngfactory-loader": "^6.0.0",
        "@tinymce/tinymce-angular": "^2.0.0",
        "aws-amplify": "^1.0.4",
        "aws-amplify-angular": "^1.0.2",
        "aws-sdk": "2.282.1",
        "bootstrap": "^4.1.3",
        "chart.js": "^2.7.2",
        "classlist.js": "^1.1.20150312",
        "core-js": "^2.5.7",
        "jquery": "^3.3.1",
        "ngx-quill": "^3.3.0",
        "popper.js": "^1.14.3",
        "quill": "^1.3.6",
        "sha1": "^1.1.1",
        "ts-loader": "^4.4.2",
        "web-animations-js": "^2.3.1",
        "zone.js": "^0.8.26"
    ,
    "devDependencies": 
        "@angular-devkit/build-angular": "~0.7.1",
        "@angular/cli": "^6.1.1",
        "@angular/compiler-cli": "^6.1.0",
        "@angular/language-service": "^6.1.0",
        "@types/jquery": "^3.3.5",
        "@types/node": "^10.5.4",
        "codelyzer": "~4.4.2",
        "cpy-cli": "^2.0.0",
        "express": "^4.16.3",
        "http-server": "^0.11.1",
        "protractor": "~5.4.0",
        "reflect-metadata": "^0.1.12",
        "rxjs": "^6.2.2",
        "ts-node": "~7.0.0",
        "tslint": "~5.11.0",
        "typescript": "~2.9.2",
        "webpack-cli": "^3.1.0"
    

angular.json 配置

  "configurations": 
                        "production": 
                            "optimization": true,
                            "outputHashing": "all",
                            "sourceMap": false,
                            "extractCss": true,
                            "namedChunks": true,
                            "aot": true,
                            "extractLicenses": true,
                            "vendorChunk": true,
                            "buildOptimizer": true,
                            "fileReplacements": [
                                "replace": "src/environments/environment.ts",
                                "with": "src/environments/environment.prod.ts"
                            ]
                        
                    

【问题讨论】:

【参考方案1】:

显然它是 bug with Ionic package,即使您不使用 ionic 也是在构建时。它已由 ionic 团队修复,但尚未由 amplify 团队更新。 所以就等新版本吧,

我可以确认,并且根据 github bug issuer 有一个等待更新的解决方法:

"compilerOptions": "keyofStringsOnly": true

这里是github issue

【讨论】:

以上是关于放大角度构建错误的主要内容,如果未能解决你的问题,请参考以下文章

尝试离子构建时出现角度firebase构建错误

由于错误无法构建角度项目:错误输出为:不推荐使用选项“vendorSourceMap”

在角度 CLI 中出现构建错误:无法重新声明块范围变量“ngDevMode”

Refreshin 角度构建在 Apache 服务器上显示 404 Not Found 错误

AWS Amplify 在没有错误日志的情况下无法构建和编译

在构建角度cli时做错误做什么 - 内存不足问题