vince
vince

Reputation: 23

AWS CDK -- Error: Cannot find module '@aws-cdk/cloud-assembly-schema' in Azure DevOps pipeline

Running my AWS CDK on Azure DevOps Pipeline, but getting this Cannot find module '@aws-cdk/cloud-assembly-schema' error. No idea what goes wrong at the moment.

Run cdk synth myStack

The pipeline yml:

trigger:
- none

pool: 
  vmImage: 'ubuntu-latest'

steps:
  
  - task: NodeTool@0
    inputs: 
      versionSpec: '16.x'
    displayName: "Install NodeJS"
  - script: | 
      echo "Check version"
      which node
      echo "Node Version: " 
      sudo node -v
      echo "NPM Version: " 
      sudo npm -v
    displayName: "Node Version check"
 

  - script: |      
      echo "Installing packages"      
      echo "Install AWS CDK"
      sudo npm install -g aws-cdk      
    displayName: 'Installing aws cdk'

  - script: |
      echo "NPM INSTALL"
      sudo  npm install
    displayName: "NPM INSTALL"

  - task: AWSShellScript@1
    inputs:
      awsCredentials: 'azure-infra-deploy-ops'
      regionName: 'ap-southeast-2'
      scriptType: 'inline'
      workingDirectory: '$(Build.SourcesDirectory)'
      inlineScript: |
        echo "Running validations"
        cdk synth myStack
    displayName: 'AWS CDK output'

Error output:

Error: Cannot find module '@aws-cdk/cloud-assembly-schema'
Require stack:
- /home/vsts/work/1/s/node_modules/@aws-cdk/core/lib/annotations.js
- /home/vsts/work/1/s/node_modules/@aws-cdk/core/lib/tag-aspect.js
- /home/vsts/work/1/s/node_modules/@aws-cdk/core/lib/index.js
- /home/vsts/work/1/s/bin/tandm-cdk.ts
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:941:15)
    at Function.Module._load (node:internal/modules/cjs/loader:774:27)
    at Module.require (node:internal/modules/cjs/loader:1013:19)
    at require (node:internal/modules/cjs/helpers:93:18)
    at Object.<anonymous> (/home/vsts/work/1/s/node_modules/@aws-cdk/core/lib/annotations.ts:1:1)
    at Module._compile (node:internal/modules/cjs/loader:1109:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1138:10)
    at Module.load (node:internal/modules/cjs/loader:989:32)
    at Function.Module._load (node:internal/modules/cjs/loader:829:14)
    at Module.require (node:internal/modules/cjs/loader:1013:19)
Subprocess exited with error 1

##[error]Error: The process '/usr/bin/bash' failed with exit code 1

Checked the node_modules in the build run time, it looks all work out:

-rw-r--r--   1 vsts docker    543 May  9 23:29 README.md
-rw-r--r--   1 vsts docker   1409 May  9 23:29 azure-pipelines-pr.yml
-rw-r--r--   1 vsts docker   1006 May  9 23:29 azure-pipelines.yml
drwxr-xr-x   2 vsts docker   4096 May  9 23:29 bin
-rw-r--r--   1 vsts docker    682 May  9 23:29 cdk.json
-rw-r--r--   1 vsts docker    130 May  9 23:29 jest.config.js
drwxr-xr-x   2 vsts docker   4096 May  9 23:29 lib
drwxr-xr-x 401 vsts docker  16384 May  9 23:29 node_modules
-rw-r--r--   1 vsts docker 282463 May  9 23:29 package-lock.json
-rw-r--r--   1 vsts docker   1195 May  9 23:29 package.json
drwxr-xr-x   2 vsts docker   4096 May  9 23:29 test
-rw-r--r--   1 vsts docker    598 May  9 23:29 tsconfig.json
/home/vsts/work/1/s
/home/vsts/work/1/s/node_modules/aws-cdk/node_modules/@aws-cdk/cloud-assembly-schema

package.json

"dependencies": {
    "@aws-cdk/aws-certificatemanager": "^1.102.0",
    "@aws-cdk/aws-cloudfront": "^1.102.0",
    "@aws-cdk/aws-cloudwatch": "^1.102.0",
    "@aws-cdk/aws-ec2": "^1.102.0",
    "@aws-cdk/aws-ecr": "^1.102.0",
    "@aws-cdk/aws-ecs": "^1.102.0",
    "@aws-cdk/aws-ecs-patterns": "^1.102.0",
    "@aws-cdk/aws-elasticloadbalancingv2": "^1.102.0",
    "@aws-cdk/aws-iam": "^1.102.0",
    "@aws-cdk/aws-logs": "^1.102.0",
    "@aws-cdk/aws-route53": "^1.102.0",
    "@aws-cdk/aws-route53-targets": "^1.102.0",
    "@aws-cdk/aws-s3": "^1.102.0",
    "@aws-cdk/aws-s3-deployment": "^1.102.0",
    "@aws-cdk/core": "1.102.0",
    "dotenv": "^8.2.0",
    "source-map-support": "^0.5.16"
  },
  "engines": { 
    "node": "16.x"
  }

Upvotes: 1

Views: 5198

Answers (2)

vince
vince

Reputation: 23

I've found the problem at the end. In short, it's the difference of npm version between the local that generating the package-lock.json and the build agent.

I've compiled the information and written into my own blog. Feel free to have a look: Lesson learn from aws cdk azure pipeline.

Upvotes: 1

Mr Qian
Mr Qian

Reputation: 23808

You have to install the missing package for aws-cdk before calling cdk synth myStack.

run this command under pipeline task:

npm i @aws-cdk/cloud-assembly-schema

Upvotes: 1

Related Questions