1

我正在运行一个有角度、放大和认知的应用程序。当我ng serve运行应用程序时出现此错误。我尝试删除所有节点模块 package-lock.json 但它没有改变任何东西所以我想知道我应该改变什么以使其在执行 ng serve 时正常工作。

ERROR in node_modules/amazon-cognito-identity-js/index.d.ts:1:1 
- error TS6200: Definitions of the following identifiers conflict with 
those in another file: NodeCallback, ClientMetadata, AuthenticationDetails, 
CognitoUser, CognitoUserAttribute, CognitoUserPool, CognitoUserSession, CognitoAccessToken, CognitoIdToken, CognitoRefreshToken, CookieStorage
declare module 'amazon-cognito-identity-js' {

node_modules/aws-amplify/node_modules/amazon-cognito-identity-js/index.d.ts:1:1
    1 declare module 'amazon-cognito-identity-js' {
    Conflicts are in this file.
4

1 回答 1

1

amazon-cognito-identity-js软件包不是必需的,并且是aws-amplify.

My modules:
    "@angular/animations": "~11.0.5",
    "@angular/cdk": "^11.0.3",
    "@angular/common": "~11.0.5",
    "@angular/compiler": "~11.0.5",
    "@angular/core": "~11.0.5",
    "@angular/forms": "~11.0.5",
    "@angular/material": "^11.0.3",
    "@angular/platform-browser": "~11.0.5",
    "@angular/platform-browser-dynamic": "~11.0.5",
    "@angular/router": "~11.0.5",
    "@aws-amplify/ui-angular": "^0.4.17-unstable.1",
    "@types/graphql": "^14.5.0",
    "angular-gridster2": "^10.1.7",
    "aws-amplify": "^3.3.14-unstable.1",
    "crypto-js": "^4.0.0",
    "ini": "^2.0.0",
    "linqts": "^1.14.3",
    "ng-dynamic-component": "^8.0.0",
    "node-fetch": "^2.6.1",
    "rxjs": "~6.6.0",
    "tslib": "^2.0.0",
    "zone.js": "~0.10.2"

write in polyfilss.ts:
(window as any).global = window;

directly into package.json:
  "browser": {
    "crypto": false
  }

app-module aws-imports:
import Amplify from 'aws-amplify';
import {AmplifyUIAngularModule} from '@aws-amplify/ui-angular';
import awsmobile from '../aws-exports.js';

Amplify.configure(awsmobile);

在 .../build/options 下的 angular.json 中:

        "allowedCommonJsDependencies": [
          "crypto-js",
          "@aws-sdk/eventstream-marshaller",
          "buffer",
          "js-cookie",
          "@aws-crypto",
          "zen-observable",
          "@aws-sdk/util-utf8-node",
          "@aws-crypto/sha256-js",
          "@aws-crypto/crc32",
          "@aws-sdk/util-buffer-from",
          "@aws-sdk/smithy-client",
          "@aws-sdk/middleware-serde",
          "@aws-sdk/middleware-user-agent",
          "@aws-sdk/middleware-retry",
          "@aws-sdk/middleware-signing",
          "@aws-sdk/middleware-content-length",
          "@aws-sdk/middleware-host-header",
          "@aws-sdk/config-resolver",
          "@aws-sdk/s3-request-presigner",
          "@aws-sdk/util-format-url",
          "@aws-sdk/util-create-request",
          "@aws-sdk/property-provider",
          "axios",
          "@aws-sdk/fetch-http-handler",
          "@aws-sdk/protocol-http",
          "@aws-sdk/querystring-builder",
          "@aws-sdk/util-utf8-browser",
          "@aws-sdk/url-parser-browser",
          "@aws-crypto/sha256-browser",
          "@aws-sdk/url-parser-node",
          "@aws-sdk/util-uri-escape",
          "@aws-sdk/middleware-sdk-s3",
          "@aws-sdk/middleware-bucket-endpoint",
          "@aws-sdk/querystring-parser",
          "@aws-sdk/middleware-apply-body-checksum",
          "@aws-sdk/middleware-ssec",
          "@aws-sdk/middleware-expect-continue",
          "fast-xml-parser",
          "@aws-sdk/xml-builder",
          "@aws-sdk/md5-js",
          "@aws-sdk/hash-blob-browser",
          "@aws-sdk/eventstream-serde-browser",
          "@aws-sdk/middleware-location-constraint",
          "uuid",
          "@aws-sdk/credential-provider-cognito-identity",
          "@aws-sdk/eventstream-serde-config-resolver",
          "@aws-sdk/client-s3",
          "@aws-sdk/client-pinpoint",
          "ulid",
          "zen-push",
          "lodash",
          "@aws-amplify/core",
          "@aws-amplify/analytics",
          "@aws-amplify/ui-components",
          "isomorphic-unfetch"
        ]

在 tsconfig.json 作为 compilerOptions 的一部分:

"paths": {
  "crypto": [
    "../../node_modules/crypto-js"
  ]
}

那么就没有更多的警告或错误了。

于 2020-12-22T22:08:26.380 回答