'aws cdk 2.0 init app fails to build with prettier issues, which is from jest-snapshot

node: v16.7.0
cdk: 2.0.0 (build 4b6ce31)

package.json:

  "devDependencies": {
    "@types/jest": "^26.0.10",
    "@types/node": "10.17.27",
    "aws-cdk": "2.0.0",
    "jest": "^26.4.2",
    "ts-jest": "^26.2.0",
    "ts-node": "^9.0.0",
    "typescript": "^3.9.7"
  },
  "dependencies": {
    "aws-cdk-lib": "2.0.0",
    "constructs": "^10.0.0",
    "source-map-support": "^0.5.16"
  }

npm run build/watch stack trace:

node_modules/@types/prettier/index.d.ts:41:54 - error TS2315: Type 'IsTuple' is not generic.

41 type IndexProperties<T extends { length: number }> = IsTuple<T> extends true
                                                        ~~~~~~~~~~

node_modules/@types/prettier/index.d.ts:53:6 - error TS2456: Type alias 'IsTuple' circularly references itself.

53 type IsTuple<T> = T extends [] ? true : T extends [infer First, ...infer Remain] ? IsTuple<Remain> : false;
        ~~~~~~~

node_modules/@types/prettier/index.d.ts:53:65 - error TS2574: A rest element type must be an array type.

53 type IsTuple<T> = T extends [] ? true : T extends [infer First, ...infer Remain] ? IsTuple<Remain> : false;
                                                                   ~~~~~~~~~~~~~~~

node_modules/@types/prettier/index.d.ts:53:84 - error TS2315: Type 'IsTuple' is not generic.

53 type IsTuple<T> = T extends [] ? true : T extends [infer First, ...infer Remain] ? IsTuple<Remain> : false;
                                                                                      ~~~~~~~~~~~~~~~

node_modules/@types/prettier/index.d.ts:96:5 - error TS2589: Type instantiation is excessively deep and possibly infinite.

96     call<
       ~~~~

node_modules/@types/prettier/index.d.ts:131:5 - error TS2589: Type instantiation is excessively deep and possibly infinite.

131     each<
        ~~~~

node_modules/@types/prettier/index.d.ts:165:5 - error TS2589: Type instantiation is excessively deep and possibly infinite.

165     map<
        ~~~

[2:30:13 PM] Found 7 errors. Watching for file changes.

I noticed prettier is coming from jest-snapshot in package-lock.json:

    "node_modules/jest-snapshot": {
      "version": "26.6.2",
      "resolved": "https://registry.npmjs.org/jest-snapshot/-/jest-snapshot-26.6.2.tgz",
      "integrity": "sha512-OLhxz05EzUtsAmOMzuupt1lHYXCNib0ECyuZ/PZOx9TrZcC8vL0x+DUG3TL+GLX3yHG45e6YGjIm0XwDc3q3og==",
      "dev": true,
      "dependencies": {
        "@babel/types": "^7.0.0",
        "@jest/types": "^26.6.2",
        "@types/babel__traverse": "^7.0.4",
        "@types/prettier": "^2.0.0",
        "chalk": "^4.0.0",
        "expect": "^26.6.2",
        "graceful-fs": "^4.2.4",
        "jest-diff": "^26.6.2",
        "jest-get-type": "^26.3.0",
        "jest-haste-map": "^26.6.2",
        "jest-matcher-utils": "^26.6.2",
        "jest-message-util": "^26.6.2",
        "jest-resolve": "^26.6.2",
        "natural-compare": "^1.4.0",
        "pretty-format": "^26.6.2",
        "semver": "^7.3.2"
      },
      "engines": {
        "node": ">= 10.14.2"
      }
    },

Any ideas?



Solution 1:[1]

I faced the issue from one moment to another and looks like this is the problem https://github.com/aws/aws-cdk/issues/20319

the suggested solution to add a fixed version of prettier to the Dev dependencies worked for me. Give it a try

{
  "devDependencies": {
    "@types/prettier": "2.6.0"
  }
}

if you're using projen for scafolding the change should be in the projen.js file

devDeps: [
    '@types/[email protected]'
]

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1