【问题标题】:TypeError: Class constructor Client cannot be invoked without 'new' with AWS S3ClientTypeError: 类构造函数客户端不能在没有使用 AWS S3Client 的 \'new\' 的情况下调用
【发布时间】:2022-10-19 02:50:27
【问题描述】:

最近,我使用 create-react-app 创建了一个 React 应用程序,我在以下行中收到错误:

const client = new S3Client({ // Here
    credentials: {
        accessKeyId: 'testingout',
        secretAccessKey: 'testing out',
    },
    endpoint: 'http://127.0.0.1:53921',
});

client
    .send(new ListBucketsCommand({}))
    .then(console.log)
    .catch(console.error)

这是我的tsconfig.json

{
  "compilerOptions": {
    "target": "es6",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noFallthroughCasesInSwitch": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react-jsx"
  },
  "include": [
    "src"
  ]
}

这是我的package.json

{
  "name": "s3-viewer",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@aws-sdk/client-s3": "^3.185.0",
    "@aws-sdk/credential-providers": "^3.186.0",
    "@aws-sdk/types": "^3.186.0",
    "@chakra-ui/react": "^2.3.5",
    "@emotion/react": "^11.10.4",
    "@emotion/styled": "^11.10.4",
    "@testing-library/jest-dom": "^5.16.5",
    "@testing-library/react": "^13.4.0",
    "@testing-library/user-event": "^13.5.0",
    "@types/jest": "^27.5.2",
    "@types/node": "^16.11.64",
    "@types/react": "^18.0.21",
    "@types/react-dom": "^18.0.6",
    "framer-motion": "^7.5.2",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-scripts": "5.0.1",
    "typescript": "^4.8.4",
    "web-vitals": "^2.1.4"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

如您所见,我拥有最新的 S3 客户端和使其工作所需的软件包。我的应用程序目前除了客户端之外什么都没有,因为我试图让它先连接。

如您所见,目标是es6,所以我真的不知道它可能是什么。我通过调用yarn start 来运行它。

【问题讨论】:

    标签: reactjs typescript amazon-web-services amazon-s3 yarnpkg


    【解决方案1】:

    我也遇到了这个问题,结果发现与类型和凭据提供程序相比,我有不同版本的 S3 客户端包:

    "@aws-sdk/client-s3": "^3.185.0",

    "@aws-sdk/credential-providers": "^3.186.0",

    "@aws-sdk/types": "^3.186.0",
    

    当我将@aws-sdk/client-s3 包升级到 3.168.0 时,问题就消失了。

    【讨论】:

      猜你喜欢
      • 2021-06-08
      • 2019-01-22
      • 1970-01-01
      • 2018-11-12
      • 2019-04-21
      • 2021-05-17
      • 2021-12-27
      • 1970-01-01
      相关资源
      最近更新 更多