Typescript: Maximum call stack size exceeded at [email protected] and @next

Created on 1 Dec 2018  路  7Comments  路  Source: microsoft/TypeScript

After installing typescript 3.2.1 I'm getting this error:

D:\git\workbench-ts\node_modules\typescript\lib\typescript.js:86983
                throw e;
                ^

RangeError: Maximum call stack size exceeded
    at isSelfReferenceLocation (D:\git\workbench-ts\node_modules\typescript\lib\typescript.js:32168:41)
    at resolveNameHelper (D:\git\workbench-ts\node_modules\typescript\lib\typescript.js:32074:21)
    at resolveName (D:\git\workbench-ts\node_modules\typescript\lib\typescript.js:31829:20)
    at resolveEntityName (D:\git\workbench-ts\node_modules\typescript\lib\typescript.js:32680:26)
    at resolveTypeReferenceName (D:\git\workbench-ts\node_modules\typescript\lib\typescript.js:38485:20)
    at getTypeFromTypeReference (D:\git\workbench-ts\node_modules\typescript\lib\typescript.js:38670:30)
    at getTypeFromTypeNode (D:\git\workbench-ts\node_modules\typescript\lib\typescript.js:40178:28)
    at getConstraintFromTypeParameter (D:\git\workbench-ts\node_modules\typescript\lib\typescript.js:38328:72)
    at fillMissingTypeArguments (D:\git\workbench-ts\node_modules\typescript\lib\typescript.js:37877:49)
    at getTypeFromClassOrInterfaceReference (D:\git\workbench-ts\node_modules\typescript\lib\typescript.js:38429:78)
error Command failed with exit code 1.

I also tried with typescript@next getting the following:

D:\git\workbench-ts\node_modules\typescript\lib\typescript.js:87007
                throw e;
                ^

RangeError: Maximum call stack size exceeded
    at isSelfReferenceLocation (D:\git\workbench-ts\node_modules\typescript\lib\typescript.js:32191:41)
    at resolveNameHelper (D:\git\workbench-ts\node_modules\typescript\lib\typescript.js:32097:21)
    at resolveName (D:\git\workbench-ts\node_modules\typescript\lib\typescript.js:31853:20)
    at resolveEntityName (D:\git\workbench-ts\node_modules\typescript\lib\typescript.js:32703:26)
    at resolveTypeReferenceName (D:\git\workbench-ts\node_modules\typescript\lib\typescript.js:38508:20)
    at getTypeFromTypeReference (D:\git\workbench-ts\node_modules\typescript\lib\typescript.js:38693:30)
    at getTypeFromTypeNode (D:\git\workbench-ts\node_modules\typescript\lib\typescript.js:40201:28)
    at getConstraintFromTypeParameter (D:\git\workbench-ts\node_modules\typescript\lib\typescript.js:38351:72)
    at fillMissingTypeArguments (D:\git\workbench-ts\node_modules\typescript\lib\typescript.js:37900:49)
    at getTypeFromClassOrInterfaceReference (D:\git\workbench-ts\node_modules\typescript\lib\typescript.js:38452:78)
error Command failed with exit code 1.

Related Issues:
I found similar issues:
https://github.com/Microsoft/TypeScript/issues/16533
https://github.com/Microsoft/TypeScript/issues/15926

But I am confident I'm not doing any circular reference.
The solution was compiling successfully before upgrading to [email protected]

My tsconfig.json:

{
  "compilerOptions": {
    /* Basic Options */
    "target": "es6" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'. */,
    "module": "esnext" /* Specify module code generation: 'none', commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
    "lib": [
      "es2017",
      "dom"
    ] /* Specify library files to be included in the compilation:  */,
    "allowJs": false /* Allow javascript files to be compiled. */,
    "jsx": "react" /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */,
    "sourceMap": true /* Generates corresponding '.map' file. */,
    "outDir": "./public/" /* Redirect output structure to the directory. */,

    /* Strict Type-Checking Options */
    "strict": true /* Enable all strict type checking options. Enabling --strict enables --noImplicitAny, --noImplicitThis, --alwaysStrict, --strictNullChecks, --strictFunctionTypes and --strictPropertyInitialization */,               /* Parse in strict mode and emit "use strict" for each source file. */

    /* Additional Checks */
    "noUnusedLocals": false /* Report errors on unused locals. */,
    "noUnusedParameters": false /* Report errors on unused parameters. */,
    "noImplicitReturns": true /* Report error when not all code paths in function return a value. */,
    "noFallthroughCasesInSwitch": true /* Report errors for fallthrough cases in switch statement. */,

    /* Module Resolution Options */
    "moduleResolution": "node" /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */,
    "baseUrl": "./src" /* Base directory to resolve non-absolute module names. */,
    "esModuleInterop": true /*Emit __importStar and __importDefault helpers for runtime babel ecosystem compatibility and enable --allowSyntheticDefaultImports for typesystem compatibility.*/,
    "allowSyntheticDefaultImports": true /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */,
    "forceConsistentCasingInFileNames": true,
    "skipLibCheck": true
  },
  "include": ["src/**/*"],
  "exclude": ["node_modules"]
}

My package.json:

{
  "name": "react-typescript",
  "version": "1.0.0",
  "description": "",
  "scripts": {
    "build": "webpack --config webpack.config.prod.js && node copyPublicFolder",
    "start": "webpack-dev-server --config webpack.config.dev.js",
    "lint": "tslint --project tsconfig.json --format stylish",
    "test": "jest --colors"
  },
  "author": "luca",
  "license": "ISC",
  "devDependencies": {
    "@types/base-64": "^0.1.2",
    "@types/classnames": "^2.2.6",
    "@types/echarts": "^4.1.3",
    "@types/history": "^4.7.2",
    "@types/jest": "^23.3.10",
    "@types/node-fetch": "^2.1.4",
    "@types/react": "^16.7.11",
    "@types/react-dom": "^16.0.11",
    "@types/react-grid-layout": "^0.16.5",
    "@types/react-redux": "^6.0.10",
    "@types/react-router": "^4.4.1",
    "@types/react-router-dom": "^4.3.1",
    "@types/react-select": "^2.0.10",
    "@types/react-test-renderer": "^16.0.3",
    "@types/react-window": "^1.1.0",
    "@types/webpack-env": "^1.13.6",
    "clean-webpack-plugin": "^1.0.0",
    "css-loader": "^1.0.1",
    "dotenv-webpack": "^1.5.7",
    "duplicate-package-checker-webpack-plugin": "^3.0.0",
    "file-loader": "^2.0.0",
    "fork-ts-checker-webpack-plugin": "^0.5.0",
    "fs-extra": "^7.0.1",
    "html-webpack-plugin": "^4.0.0-beta.3",
    "jest": "^23.6.0",
    "jest-pnp-resolver": "^1.0.2",
    "jest-resolve": "^23.6.0",
    "mini-css-extract-plugin": "^0.4.5",
    "node-fetch": "^2.3.0",
    "optimize-css-assets-webpack-plugin": "^5.0.1",
    "pnp-webpack-plugin": "^1.2.1",
    "postcss-flexbugs-fixes": "^4.1.0",
    "postcss-js": "^2.0.0",
    "postcss-loader": "^3.0.0",
    "postcss-preset-env": "^6.4.0",
    "postcss-safe-parser": "^4.0.1",
    "react-test-renderer": "^16.6.3",
    "redux-devtools-extension": "^2.13.7",
    "style-loader": "^0.23.1",
    "terser-webpack-plugin": "^1.1.0",
    "ts-jest": "^23.10.5",
    "ts-loader": "^5.3.1",
    "tsconfig-paths-webpack-plugin": "^3.2.0",
    "tslint": "^5.11.0",
    "tslint-loader": "^3.6.0",
    "tslint-react": "^3.6.0",
    "typescript": "^3.2.1",
    "url-loader": "^1.1.2",
    "webpack": "^4.26.1",
    "webpack-cli": "^3.1.2",
    "webpack-dev-server": "^3.1.10",
    "webpack-manifest-plugin": "^2.0.4",
    "workbox-webpack-plugin": "^3.6.3"
  },
  "dependencies": {
    "@material-ui/core": "^3.6.0",
    "@material-ui/icons": "^3.0.1",
    "base-64": "^0.1.0",
    "classnames": "^2.2.6",
    "echarts": "^4.2.0-rc.2",
    "echarts-for-react": "^2.0.15-beta.0",
    "history": "^4.7.2",
    "immutability-helper": "^2.8.1",
    "normalizr": "^3.3.0",
    "react": "^16.6.3",
    "react-dom": "^16.6.3",
    "react-grid-layout": "^0.16.6",
    "react-redux": "^5.1.1",
    "react-router": "^4.3.1",
    "react-router-dom": "^4.3.1",
    "react-select": "^2.1.2",
    "react-window": "^1.2.4",
    "redux": "^4.0.1",
    "redux-observable": "^1.0.0",
    "reselect": "^4.0.0",
    "rxjs": "^6.3.3",
    "storm-react-diagrams": "^5.2.1",
    "typeface-roboto": "^0.0.54"
  },
  "browserslist": [
    ">0.2%",
    "not dead",
    "not ie <= 11",
    "not op_mini all"
  ]
}
Bug Crash

Most helpful comment

This is fixed in 3.3.3333.

All 7 comments

Is your code really "heavy" on generics?

[EDIT]

I ask because I have projects with a lot of.. Err.. Complex generic types and they failed when I tried to upgrade. I took that as an opportunity to rewrite the projects, though.

I'm getting this as well for a project that is heavy on generic types.

After a thorough investigation I found that it is one of my dependencies that's causing the issue.
I just reported an issue on the github repo.
https://github.com/projectstorm/react-diagrams/issues/307

If the issue reported here is not relevant it can be closed.
Thank you.

Is it possible that extending and adding the same generic default causes the crash?

export class BaseWidget<P extends BaseWidgetProps = BaseWidgetProps, S = any> extends React.Component<P, S> {
  // Beautiful code...
}

I'm taking about this: P extends BaseWidgetProps = BaseWidgetProps

I haven't been able to build a small reproduction yet, but lodash typings definitely seem to be a large contributor (~4.14.90+). Removing them works around the stack out for us鈥攂ut it only occurs in some of our more complicated projects

@sandersn we at least need a root cause here before 3.4 goes out

This is fixed in 3.3.3333.

Was this page helpful?
0 / 5 - 0 ratings