简体   繁体   English

将 aws cdk 与 typescript 结合使用时出现许多构建错误

[英]Many build errors while using aws cdk in combination with typescript

I am currently stuck with my tsc build: May someone of you can help me out.我目前坚持使用我的 tsc 构建:愿你们中的某个人可以帮助我。

I was trying to build my Serverless project with nom run build .我试图用nom run build构建我的无服务器项目。

After some time I get following errors:一段时间后,我收到以下错误:

lambda-fun/fetch-notification.ts:13:22 - error TS2694: Namespace '"/Users/elmar/dev/my-project/node_modules/aws-cdk-lib/aws-lambda/index"' has no exported member 'APIGatewayProxyEventV2'.
13 event: awsLambda.APIGatewayProxyEventV2,

lambda-fun/fetch-notification.ts:14:22 - error TS2694: Namespace '"/Users/elmar/dev/my-project/node_modules/aws-cdk-lib/aws-lambda/index"' has no exported member 'APIGatewayProxyResultV2'.
14 ): Promise<awsLambda.APIGatewayProxyResultV2> {
node_modules/fetch-blob/file.d.ts:1:76 - error TS7017: Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature.
1 /** @type {typeof globalThis.File} */ export const File: typeof globalThis.File;
node_modules/fetch-blob/from.d.ts:20:64 - error TS2749: 'File' refers to a value, but is being used as a type here. Did you mean 'typeof File'?
20 export function fileFrom(path: string, type?: string): Promise<File>;
node_modules/fetch-blob/from.d.ts:25:60 - error TS2749: 'File' refers to a value, but is being used as a type here. Did you mean 'typeof File'?
25 export function fileFromSync(path: string, type?: string): File;
node_modules/fetch-blob/index.d.ts:2:38 - error TS7017: Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature.
2 export const Blob: typeof globalThis.Blob;
node_modules/formdata-polyfill/esm.min.d.ts:2:11 - error TS2749: 'FormData' refers to a value, but is being used as a type here. Did you mean 'typeof FormData'?
2   new (): FormData;
node_modules/formdata-polyfill/esm.min.d.ts:3:14 - error TS2749: 'FormData' refers to a value, but is being used as a type here. Did you mean 'typeof FormData'?
3   prototype: FormData;
node_modules/formdata-polyfill/esm.min.d.ts:5:50 - error TS2749: 'FormData' refers to a value, but is being used as a type here. Did you mean 'typeof FormData'?
5 export declare function formDataToBlob(formData: FormData): Blob;
node_modules/node-fetch/@types/index.d.ts:124:4 - error TS2749: 'FormData' refers to a value, but is being used as a type here. Did you mean 'typeof FormData'?
124  | FormData
node_modules/node-fetch/@types/index.d.ts:137:22 - error TS2749: 'FormData' refers to a value, but is being used as a type here. Did you mean 'typeof FormData'?
137  formData(): Promise<FormData>;

Found 11 errors in 6 files.
Errors  Files
     2  lambda-fun/fetch-notification.ts:13
     1  node_modules/fetch-blob/file.d.ts:1
     2  node_modules/fetch-blob/from.d.ts:20
     1  node_modules/fetch-blob/index.d.ts:2
     3  node_modules/formdata-polyfill/esm.min.d.ts:2
     2  node_modules/node-fetch/@types/index.d.ts:124

So I am defenitly lost there.所以我肯定迷路了。 May you need some info from my package.json :你可能需要我的package.json的一些信息:

"scripts": {
    "build": "tsc",
    "watch": "tsc -w",
    "test": "jest",
    "cdk": "cdk"
  },
  "devDependencies": {
    "@types/aws-lambda": "^8.10.104",
    "@types/jest": "^28.1.6",
    "@types/node": "18.7.18",
    "@types/node-fetch": "^2.6.2",
    "@types/prettier": "2.7.0",
    "@types/uuid": "^8.3.4",
    "aws-cdk": "2.41.0",
    "constructs": "^10.1.71",
    "esbuild": "^0.15.0",
    "jest": "^28.1.3",
    "ts-jest": "^28.0.7",
    "ts-node": "^10.9.1",
    "typescript": "^4.7.4"
  },
  "dependencies": {
    "@aws-cdk/aws-dynamodb": "^1.169.0",
    "aws-cdk-lib": "^2.41.0",
    "aws-sdk": "^2.1217.0",
    "constructs": "^10.0.0",
    "fast-xml-parser": "^4.0.9",
    "fetch": "^1.1.0",
    "node-fetch": "^3.2.10",
    "source-map-support": "^0.5.21",
    "twitter-api-sdk": "^1.1.0",
    "ulid": "^2.3.0",
    "uuid": "^8.3.2"
  }

If you need additional information please let me know.如果您需要更多信息,请告诉我。 Thank you.谢谢你。

Treueid this already: typescript: error TS2693: 'Promise' only refers to a type, but is being used as a value here Treueid 这已经: typescript:错误 TS2693:“承诺”仅指一种类型,但在此处用作值

I was running into the same issue with node-fetch in a CDK project and fixed it by adding "DOM" to the lib array in my tsconfig.json :我在 CDK 项目中遇到了与node-fetch相同的问题,并通过将"DOM"添加到我的tsconfig.json中的lib数组来修复它:

Before:前:

"lib": [
  "es2018"
],

After:后:

"lib": [
  "es2018",
  "DOM"
],

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM