Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSII compilation issues #3864

Closed
kpalaparthi opened this issue Nov 30, 2022 · 7 comments
Closed

JSII compilation issues #3864

kpalaparthi opened this issue Nov 30, 2022 · 7 comments
Labels
bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.

Comments

@kpalaparthi
Copy link

kpalaparthi commented Nov 30, 2022

Describe the bug

Unable to compile the code getting compilation errors

Expected Behavior

Compilation should work as expected

Current Behavior

COmpilation is getting failed

[2022-11-30T15:30:29.462] [ERROR] jsii/compiler - Compilation errors prevented the JSII assembly from being created
node_modules/@types/babel__traverse/index.d.ts:68:50 - error TS1005: ']' expected.

68 export type ArrayKeys = keyof { [P in keyof T as T[P] extends any[] ? P : never]: P };
~~
node_modules/@types/babel__traverse/index.d.ts:68:53 - error TS1005: ';' expected.

68 export type ArrayKeys = keyof { [P in keyof T as T[P] extends any[] ? P : never]: P };
~
node_modules/@types/babel__traverse/index.d.ts:68:58 - error TS1005: ';' expected.

68 export type ArrayKeys = keyof { [P in keyof T as T[P] extends any[] ? P : never]: P };
~~~~~~~
node_modules/@types/babel__traverse/index.d.ts:68:70 - error TS1011: An element access expression should take an argument.

68 export type ArrayKeys = keyof { [P in keyof T as T[P] extends any[] ? P : never]: P };

node_modules/@types/babel__traverse/index.d.ts:68:83 - error TS1005: ';' expected.

68 export type ArrayKeys = keyof { [P in keyof T as T[P] extends any[] ? P : never]: P };
~
node_modules/@types/babel__traverse/index.d.ts:68:84 - error TS1128: Declaration or statement expected.

68 export type ArrayKeys = keyof { [P in keyof T as T[P] extends any[] ? P : never]: P };
~
node_modules/@types/babel__traverse/index.d.ts:68:88 - error TS1128: Declaration or statement expected.

68 export type ArrayKeys = keyof { [P in keyof T as T[P] extends any[] ? P : never]: P };
~
👾 Task "compile" failed when executing "jsii --silence-warnings=reserved-word --no-fix-peer-dependencies" (cwd: /Users/krishnakanth/Documents/code/cdk/cdk-resources)

Reproduction Steps

We are using aws-cdk-lib 2.43.1 with jest and other things.
Npx projen compile is getting failed

Below is the package.json

{
  "name": "@cdk/cdk-resources",
  "repository": {
    "type": "git",
    "url": ""
  },
  "scripts": {
    "build": "npx projen build",
    "bump": "npx projen bump",
    "clobber": "npx projen clobber",
    "compat": "npx projen compat",
    "compile": "npx projen compile",
    "default": "npx projen default",
    "eject": "npx projen eject",
    "eslint": "npx projen eslint",
    "gendoc": "npx projen gendoc",
    "package": "npx projen package",
    "package-all": "npx projen package-all",
    "package:java": "npx projen package:java",
    "package:js": "npx projen package:js",
    "package:python": "npx projen package:python",
    "post-compile": "npx projen post-compile",
    "post-upgrade": "npx projen post-upgrade",
    "pre-compile": "npx projen pre-compile",
    "release": "npx projen release",
    "test": "npx projen test",
    "test:update": "npx projen test:update",
    "test:watch": "npx projen test:watch",
    "unbump": "npx projen unbump",
    "upgrade": "npx projen upgrade",
    "watch": "npx projen watch",
    "projen": "npx projen"
  },
  "author": {
    "name": "user",
    "email": "user@domain.com",
    "organization": false
  },
  "devDependencies": {
    "@types/jest": "^27.5.2",
    "@types/node": "^12",
    "@types/prettier": "2.6.0",
    "@types/babel__traverse": "^7.18.1",
    "@typescript-eslint/eslint-plugin": "^5",
    "@typescript-eslint/parser": "^5",
    "aws-cdk-lib": "2.43.1",
    "constructs": "10.0.5",
    "esbuild": "^0.14.53",
    "eslint": "^8",
    "eslint-import-resolver-node": "^0.3.6",
    "eslint-import-resolver-typescript": "^2.7.1",
    "eslint-plugin-import": "^2.26.0",
    "ignore": "^5.2.0",
    "jest": "^27",
    "jest-junit": "^13",
    "jsii": "^1.63.2",
    "jsii-diff": "^1.63.2",
    "jsii-pacmak": "^1.63.2",
    "json-schema": "^0.4.0",
    "npm-check-updates": "^12",
    "projen": "^0.54.22",
    "source-map-support": "^0.5.21",
    "standard-version": "^9",
    "ts-jest": "^27",
    "typedoc": "*",
    "typedoc-plugin-missing-exports": "*",
    "typedoc-plugin-no-inherit": "^1.3.1",
    "typescript": "^4.7.4"
  },
  "peerDependencies": {
    "aws-cdk-lib": "^2.43.1",
    "constructs": "^10.0.5"
  },
  "dependencies": {
    "@types/js-yaml": "*",
    "@types/uuid": "^8.3.4",
    "cdk-nag": "2.15.32",
    "deepmerge": "^4.2.2",
    "js-yaml": "^4.1.0",
    "uuid": "^8.3.2"
  },
  "bundledDependencies": [
    "@types/js-yaml",
    "@types/uuid",
    "deepmerge",
    "js-yaml",
    "uuid"
  ],
  "keywords": [
    "cdk"
  ],
  "main": "lib/index.js",
  "license": "Apache-2.0",
  "version": "0.0.0",
  "jest": {
    "collectCoverageFrom": [
      "./src/**/**.ts"
    ],
    "coverageThreshold": {
      "global": {
        "lines": 40
      }
    },
    "preset": "ts-jest",
    "globals": {
      "ts-jest": {
        "tsconfig": "tsconfig.dev.json"
      }
    },
    "clearMocks": true,
    "collectCoverage": true,
    "coverageReporters": [
      "json",
      "lcov",
      "clover",
      "cobertura",
      "text"
    ],
    "coverageDirectory": "coverage",
    "coveragePathIgnorePatterns": [
      "/node_modules/"
    ],
    "testPathIgnorePatterns": [
      "/node_modules/"
    ],
    "watchPathIgnorePatterns": [
      "/node_modules/"
    ],
    "testMatch": [
      "**/__tests__/**/*.[jt]s?(x)",
      "**/?(*.)+(spec|test).[tj]s?(x)"
    ],
    "reporters": [
      "default",
      [
        "jest-junit",
        {
          "outputDirectory": "test-reports"
        }
      ]
    ]
  },
  "types": "lib/index.d.ts",
  "stability": "stable",
  "jsii": {
    "outdir": "dist",
    "targets": {
      "java": {
        "package": "com.cdk.resources",
        "maven": {
          "groupId": "com.cdk",
          "artifactId": "cdk_resources"
        }
      },
      "python": {
        "distName": "cdk_resources",
        "module": "cdk_resources"
      }
    },
    "tsc": {
      "outDir": "lib",
      "rootDir": "src"
    }
  },
  "//": "~~ Generated by projen. To modify, edit .projenrc.js and run \"npx projen\"."
}

Possible Solution

No response

Additional Information/Context

No response

SDK version used

2.43.1

Environment details (OS name and version, etc.)

MAC Ventura

@kpalaparthi kpalaparthi added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Nov 30, 2022
@RomainMuller
Copy link
Contributor

RomainMuller commented Nov 30, 2022

[2022-11-30T15:30:29.462] [ERROR] jsii/compiler - Compilation errors prevented the JSII assembly from being created node_modules/@types/babel__traverse/index.d.ts:68:50 - error TS1005: ']' expected.

Looks like some of your dependencies are using syntax that is not supported by TypeScript 3.9, which jsii is built on. If you do not directly use these babel types in your own code, you might be able to solve your issue by configuring jsii.tsc.types in your package.json. Often, node is the only necessary one (but YMMV):

/// package.json (only showing the relevant keys)
{
	"jsii": {
		"tsc": {
			"types": ["node"],
			// ...
		},
		// ...
	},
	// ...
}

RFC-373 is preparing us to implement a strategy that will allow us to move to newer TypeScript releases, hopefully really soon.

@GEMISIS
Copy link

GEMISIS commented Jan 9, 2023

@kpalaparthi For the Babel types, a temporary solution is to hardcode @types/babel__traverse to version 7.18.2, then downgrade TypeScript to 3.9.7.

@RomainMuller Is there an ETA on getting the newer version of TypeScript issue resolved? This is insane that JSII is stuck on an ancient version of TypeScript still. It looks like that PR has been stuck in limbo since your comment?

@RomainMuller
Copy link
Contributor

@GEMISIS - this is becoming more of a problem every day, so we're looking to prioritize this work.

@greg5123334
Copy link

The following configuration in package.json allows me to complete npm run build:

"tsc": {
    "types": [
    "node",   <---- To workaround original issue
    "jest"    <---- To workaround error below
    ]
},

error TS2593: Cannot find name 'test'. Do you need to install type definitions for a test runner? Try npm i @types/jest or npm i @types/mocha and then add jest or mocha to the types field in your tsconfig.

  "devDependencies": {
    "@types/babel__traverse": "7.18.2",
    "@types/jest": "26.0.24",
    "@types/node": "18.11.18",
    "aws-cdk-lib": "2.60.0",
    "constructs": "10.0.0",
    "jest": "^29.3.1",
    "jsii": "^1.73.0",
    "jsii-pacmak": "^1.73.0",
    "ts-jest": "26.2.0",
    "typescript": "3.9.7"
  },

@RichiCoder1
Copy link

Just ran into this issue where it appears JSII and picking up (and failing on) the @types/node types: https://github.com/RichiCoder1/elastic-serverless-forwarder-cdk/actions/runs/4357841257/jobs/7617647680

@mrgrain
Copy link
Contributor

mrgrain commented Feb 22, 2024

This has been resolved by publishing newer version of jsii-compiler that are compatible with newer versions of TS.

@mrgrain mrgrain closed this as completed Feb 22, 2024
Copy link
Contributor

This issue is now closed. Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.
Projects
None yet
Development

No branches or pull requests

6 participants