software.amazon.jsii.JsiiException: Module ‘@company/cdk-tagsModule’ not found

I am trying to use one of our internal generated java library by JSII from Typescript aws-cdk-library project.

when we try to invoke and on cdk synth we are getting below error

software.amazon.jsii.JsiiException: Module ‘@company/cdk-tags’ not found Error: Module ‘@company/cdk-tags’ not found

Currently we are using cdk version 1.106.0 , java 13 and maven 3.6.

here is our package.json and module-package.json

package.json

  "name": "aws-cdk-library",
  "version": "0.0.0",
  "description": "company's AWS CDK Library.",
  "author": {
    "name": "company",
    "url": "https://www.company.com",
    "organization": true
  },
  "scripts": {
    "build": "lerna run build --stream --sort --concurrency=1",
    "clean": "lerna clean",
    "deploy": "lerna publish --no-push --no-git-tag-version --force-publish --yes",
    "eslint": "eslint . --ext=.js,.ts --format=node_modules/eslint-formatter-pretty",
    "install": "lerna bootstrap",
    "lint": "eslint . --ext .js,.ts --ignore-path=.gitignore",
    "package": "lerna run package --stream --sort --concurrency=1",
    "publish-mvn": "lerna run publish-mvn --stream --sort --concurrency=1",
    "test": "jest",
    "test:ci": "jest --ci --runInBand",
    "setVersion": "lerna version --no-push --no-git-tag-version --force-publish --yes",
    "watch": "lerna run watch --parallel"
  },
  "devDependencies": {
    "@aws-cdk/assert": "1.106.0",
    "@aws-cdk/aws-certificatemanager": "1.106.0",
    "@aws-cdk/aws-cloudfront": "1.106.0",
    "@aws-cdk/aws-cloudwatch": "1.106.0",
    "@aws-cdk/aws-cloudwatch-actions": "1.106.0",
    "@aws-cdk/aws-lambda": "1.106.0",
    "@aws-cdk/aws-route53": "1.106.0",
    "@aws-cdk/aws-route53-targets": "1.106.0",
    "@aws-cdk/aws-s3": "1.106.0",
    "@aws-cdk/aws-s3-deployment": "1.106.0",
    "@aws-cdk/aws-sns": "1.106.0",
    "@aws-cdk/aws-sns-subscriptions": "1.106.0",
    "@aws-cdk/aws-synthetics": "1.106.0",
    "@aws-cdk/core": "1.106.0",
    "@aws-solutions-constructs/aws-cloudfront-s3": "1.106.0",
    "@aws-solutions-constructs/core": "1.106.0",
    "@types/jest": "^26.0.23",
    "@types/node": "^15.0.0",
    "@typescript-eslint/eslint-plugin": "^4.22.0",
    "@typescript-eslint/parser": "^4.22.0",
    "constructs": "^3.3.75",
    "eslint": "^7.25.0",
    "eslint-config-tc": "^19.0.0",
    "eslint-config-typescript-tc": "^3.0.0",
    "eslint-formatter-pretty": "^4.0.0",
    "eslint-plugin-eslint-comments": "^3.2.0",
    "eslint-plugin-import": "^2.22.1",
    "eslint-plugin-jest": "^24.3.6",
    "eslint-plugin-prettier": "^3.4.0",
    "eslint-plugin-unicorn": "^33.0.0",
    "jest": "^26.6.3",
    "jsii": "^1.30.0",
    "jsii-pacmak": "^1.30.0",
    "jsii-release": "^0.2.9",
    "lerna": "^4.0.0",
    "prettier": "^2.2.1",
    "ts-jest": "^26.5.5",
    "ts-node": "^10.0.0",
    "typescript": "^4.2.4"
  },
  "dependencies": {
    "@company/cdk-route53-cloudfront-s3": "file:packages/route53-cloudfront-s3",
    "@company/cdk-cloudwatch": "file:packages/cloudwatch",
    "@company/cdk-nodejs-canary": "file:packages/nodejs-canary",
    "@company/cdk-pagerduty-alarm-action": "file:packages/pagerduty-alarm-action",
    "@company/cdk-tags": "file:packages/tags"
  },
  "engines": {
    "node": ">=14.0.0",
    "npm": ">=6.0.0"
  },
  "private": true,
  "license": "UNLICENSED"
}```

** module-package.json **

{
  "name": "@company/cdk-tags",
  "version": "0.0.0",
  "description": "A helper library for setting required AWS Tags.",
  "keywords": [
    "aws",
    "cdk"
  ],
  "repository": {
    "type": "git",
    "url": "git+................"
  },
  "author": {
    "name": "company",
    "url": "..........",
    "organization": true
  },
  "license": "UNLICENSED",
  "bugs": {
    "url": "..............."
  },
  "homepage": ".......................",
  "main": "lib/index.js",
  "types": "lib/index.d.ts",
  "scripts": {
    "build": "jsii",
    "watch": "jsii -w",
    "package": "jsii-pacmak",
    "publish-mvn": "jsii-release-maven"
  },
  "jsii": {
    "outdir": "dist",
    "targets": {
      "java": {
        "package": "com.company.common.aws.cdk",
        "maven": {
          "groupId": "com.company.common.aws.cdk",
          "artifactId": "tags"
        }
      }
    }
  },
  "devDependencies": {
    "@aws-cdk/assert": "1.106.0",
    "@aws-cdk/aws-sns": "1.106.0"
  },
  "peerDependencies": {
    "@aws-cdk/core": "1.106.0",
    "constructs": "^3.2.84"
  }
}

Answer

Finally we are able to solve this issue. This was due to multiple modules with same java package structure names. This created a conflict in loading and finding the module when running from java.

After changing the package structure, it started working fine.

We have multiple modules like cloudwatch and nodejs-canary inside a main project.

Before

package.json for cloudwatch

“jsii”: { “outdir”: “dist”, “targets”: { “java”: { “package”: “com.company.common.aws.cdk“, “maven”: { “groupId”: “com.company.common.aws.cdk”, “artifactId”: “cloudwatch” } } } }

package.json for nodejs-canary

“jsii”: { “outdir”: “dist”, “targets”: { “java”: { “package”: “com.company.common.aws.cdk“, “maven”: { “groupId”: “com.company.common.aws.cdk”, “artifactId”: “nodejs-canary” } } } }


After

“jsii”: { “outdir”: “dist”, “targets”: { “java”: { “package”: “com.company.common.aws.cdk.cloudwatch“, “maven”: { “groupId”: “com.company.common.aws.cdk”, “artifactId”: “cloudwatch” } } } }

package.json

“jsii”: { “outdir”: “dist”, “targets”: { “java”: { “package”: “com.company.common.aws.cdk.nodejs_canary“, “maven”: { “groupId”: “com.company.common.aws.cdk”, “artifactId”: “nodejs-canary” } } } }


Just to add little more, initially when we ran with one module it worked fine. Later after adding additional modules while using in Java we got Module not found error.