簡體   English   中英

AWS CDK 代碼管道開發 - 錯誤 TS1005:預期為“]”

[英]AWS CDK Code Pipeline Development - error TS1005: ']' expected

問題:我正在使用 CDK 中的aws-cdk-lib/pipelines庫構建new CodePipeline ,並且在代碼構建階段面臨 typescript 錯誤。

錯誤信息:

文件夾結構縮寫

[Container] 2023/01/03 07:48:21 Running command npm run build

> template@0.1.0 build
> tsc

intoMagentoQueueConsumer/node_modules/axios/index.d.ts(6,18): error TS1005: ']' expected.
intoMagentoQueueConsumer/node_modules/axios/index.d.ts(6,21): error TS1005: ';' expected.
intoMagentoQueueConsumer/node_modules/axios/index.d.ts(6,35): error TS1005: '(' expected.
intoMagentoQueueConsumer/node_modules/axios/index.d.ts(6,36): error TS1135: Argument expression expected.
intoMagentoQueueConsumer/node_modules/axios/index.d.ts(6,50): error TS1005: ')' expected.
intoMagentoQueueConsumer/node_modules/axios/index.d.ts(7,1): error TS1128: Declaration or statement expected.

[Container] 2023/01/03 07:48:36 Command did not exit successfully npm run build exit status 2
[Container] 2023/01/03 07:48:36 Phase complete: BUILD State: FAILED
[Container] 2023/01/03 07:48:36 Phase context status code: COMMAND_EXECUTION_ERROR Message: Error while executing command: npm run build. Reason: exit status 2

我已經包含了 TS1135 和 TS1128 的其他錯誤消息作為上下文,因為它們可能都是相關的。

CDK 代碼管道堆棧:

請注意,在我的命令中,我cd進入每個 Lambda,使用npm ci安裝它,然后cd出來。 我刪除了這段代碼,因為它非常冗長。 它位於commands鍵值對的頂部。 tsc -v生成最新的 TypeScript 版本。

this.codePipeline = new CodePipeline(this, `${environment}-${appName}-`, {
  pipelineName: `${environment}-${appName}-`,
  selfMutation: true,
  crossAccountKeys: false,
  role: this.codePipelineRole,
  synth: new ShellStep("Deployment", {
    input: CodePipelineSource.codeCommit(this.codeRepository, environment, {  codeBuildCloneOutput: true }),
    installCommands: ["npm i -g npm@latest", "npm install -g typescript"],
    commands: [
      "tsc -v", 
      "npm ci",
      "npm run build",
      "cdk synth",
    ],
  })
});

Lambda Function package.json:

{
  "name": "intomagentoqueueconsumer",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@aws-sdk/client-sfn": "^3.226.0",
    "axios": "^1.2.1",
    "axios-retry": "^3.3.1"
  }
}

Lambda Function 在 CDK 中構建:

this.intoMagentoQueueConsumer = new NodejsFunction(this, `intoMagentoQueueConsumer`, {
  runtime: Runtime.NODEJS_16_X,
  memorySize: 1024,
  handler: "handler",
  depsLockFilePath: join(__dirname, "../../src/lambda-handlers/queue-consumers/intoMagentoQueueConsumer/package-lock.json"),
  entry: join(__dirname, "../../src/lambda-handlers/queue-consumers/intoMagentoQueueConsumer/index.ts"),
  bundling: { 
    minify: false,
    nodeModules: ["@aws-sdk/client-sfn", "axios", "axios-retry"],
    externalModules: ["aws-sdk", "crypto-js"],
   },
});

編輯:我已將 typescript 的安裝命令更改為npm install -g typescript --save-dev並獲得了 4.9.4 版本。 但是,這並沒有解決問題。

要解決此問題:

  1. 確保所有NodejsFunction代碼都引用根 package.json 文件並且沒有它自己的 package.json
  2. 確保在開發依賴項中安裝了最新版本的 Typescript(我的是 4.9.4)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM