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

Cannot read property 'jsDocCache' of undefined crash on 4.2.2 #42957

Closed
airhorns opened this issue Feb 25, 2021 · 6 comments · Fixed by #42971
Closed

Cannot read property 'jsDocCache' of undefined crash on 4.2.2 #42957

airhorns opened this issue Feb 25, 2021 · 6 comments · Fixed by #42971
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue

Comments

@airhorns
Copy link

airhorns commented Feb 25, 2021

Bug Report

tsc crashes with a TypeError when compiling TS code with lots of JSDocs:

$ /Users/airhorns/Code/gadget/node_modules/.bin/tsc --noEmit
/Users/airhorns/Code/gadget/node_modules/typescript/lib/tsc.js:88051
                throw e;
                ^

TypeError: Cannot read property 'jsDocCache' of undefined
    at getJSDocTagsWorker (/Users/airhorns/Code/gadget/node_modules/typescript/lib/tsc.js:9124:25)
    at getFirstJSDocTag (/Users/airhorns/Code/gadget/node_modules/typescript/lib/tsc.js:9144:24)
    at Object.getJSDocDeprecatedTag (/Users/airhorns/Code/gadget/node_modules/typescript/lib/tsc.js:9066:16)
    at addDeprecatedSuggestionWorker (/Users/airhorns/Code/gadget/node_modules/typescript/lib/tsc.js:36388:119)
    at addDeprecatedSuggestion (/Users/airhorns/Code/gadget/node_modules/typescript/lib/tsc.js:36397:20)
    at checkAliasSymbol (/Users/airhorns/Code/gadget/node_modules/typescript/lib/tsc.js:64716:21)
    at checkImportBinding (/Users/airhorns/Code/gadget/node_modules/typescript/lib/tsc.js:64723:13)
    at Object.forEach (/Users/airhorns/Code/gadget/node_modules/typescript/lib/tsc.js:128:30)
    at checkImportDeclaration (/Users/airhorns/Code/gadget/node_modules/typescript/lib/tsc.js:64754:36)
    at checkSourceElementWorker (/Users/airhorns/Code/gadget/node_modules/typescript/lib/tsc.js:65176:28)
error Command failed with exit code 1.

🔎 Search Terms

TypeError jsdoccache getJSDocTagsWorker

🕗 Version & Regression Information

  • This is a crash
  • This changed between versions 4.2.1 and 4.2.2

💻 Code

I am not sure which file in my project is causing this crash -- is there a hidden verbose compiler option that would indicate which file it's working on?

My tsconfig:

{
    "compilerOptions": {
        "strict": true,
        "esModuleInterop": true,
        "allowJs": true,
        "noImplicitAny": true,
        "sourceMap": true,
        "experimentalDecorators": true,
        "emitDecoratorMetadata": true,
        "forceConsistentCasingInFileNames": true,
        "useDefineForClassFields": true,
        "target": "es2020",
        "lib": [
            "es2020",
            "dom"
        ],
        "skipLibCheck": true,
        "resolveJsonModule": true,
        "baseUrl": "./",
        "moduleResolution": "node",
        "module": "commonjs",
        "jsx": "react",
        "types": [
            "jest",
            "@starscream/core/type-extensions/fastify-routes",
            "@starscream/core/type-extensions/pino",
            "@starscream/core/type-extensions/pino-pretty"
        ],
        "noEmit": true
    },
    "files": [ ... ],
    "include": [
        "./src",
        "./tools",
        "./spec",
        "./starscream.config.ts",
        "./types/gadget-fastify-extensions.d.ts"
    ],
    "exclude": [
        "node_modules",
        "spec/integration/typescript-client/fixtures"
    ]
}

🙁 Actual behavior

tsc crashes trying to compile an unspecified file

🙂 Expected behavior

tsc should succeed compiling the file or log an error to the console

@RyanCavanaugh RyanCavanaugh added this to the TypeScript 4.2.2 milestone Feb 25, 2021
@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Feb 25, 2021
@sandersn
Copy link
Member

Well, the fix is probably straightforward, but I'm not sure how to write a test for an import alias with no declarations.

@airhorns There's no verbose compiler option, but you can edit /Users/airhorns/Code/gadget/node_modules/typescript/lib/tsc.js to show the offending import:

Below the line starting: if (ts.isImportSpecifier(node) && ts.every(target.declarations, ...., add
console.log(ts.getSourceFileOfNode(node), ts.getTextOfNode(node)) (it's line 77509 on my build, but will be slightly different on yours)

@airhorns
Copy link
Author

Yup, same as #42956 I think, the node in question seems to be the NotFound in

import { NotFound } from "http-errors"

With that module installed and with @types/http-errors installed a file with just that content triggers the error.

@sandersn
Copy link
Member

sandersn commented Feb 25, 2021

Interesting, this is a pure Typescript error. That discounts my worry that it was from a change in commonjs exports.

The repro is the same so I'm going to close #42956 now.

@sandersn
Copy link
Member

Properties created by a non-homomorphic mapped type (like NotFound from Record<'NotFound' | ..., HttpErrorConstructor>) don't have declarations. I'm not sure that's correct. I'm going to track down the offending commit to help decide.

@sandersn
Copy link
Member

Also, I have a small repro now:

// @filename: errors.d.ts
export = X
declare const X: X.Names
declare namespace X {
  type Names = { [P in 'NotFound']: unknown }
}
// @filename: use.ts
import ( NotFound } from './errors'

@airhorns
Copy link
Author

Bless your heart @sandersn ! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants