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

Bug: Cannot read properties of undefined (reading 'at') coming from typescript-eslint #8075

Closed
4 tasks done
anthonyshew opened this issue Dec 15, 2023 · 7 comments
Closed
4 tasks done
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@anthonyshew
Copy link

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have searched for related issues and found none that matched my issue.
  • I have read the FAQ and my problem is not listed.

Issue Description

NOTE: I asked @JoshuaKGoldberg for help thinking I had something misconfigured - but he's confident this is a bug. He thinks he already has the problematic code cornered. Because of this, I won't be providing a reproduction - but I am more than happy to if it ends up being needed!

While upgrading dependencies and reconfiguring our monorepo, I ran into this stack trace coming from typescript-eslint. You'll want to click the > docs:lint on line 276 to expand the error.

Reproduction Repository Link

See NOTE above.

Repro Steps

Provided to me by Josh:

  1. Clone repo (https://github.com/vercel/turbo)
  2. Start a pnpm i
  3. npx eslint docs/components/Authors.tsx

Versions

package version
@typescript-eslint/eslint-plugin ^6.14.0
@typescript-eslint/parser ^6.14.0
TypeScript 5.3.3
ESLint ^8.55.0
node 18.18.2
@anthonyshew anthonyshew added bug Something isn't working triage Waiting for team members to take a look labels Dec 15, 2023
@JoshuaKGoldberg
Copy link
Member

Can confirm! This is the error report:

joshgoldberg ~/repos/turbo $ npx eslint docs/components/Authors.tsx

Oops! Something went wrong! :(

ESLint: 8.55.0

TypeError: Cannot read properties of undefined (reading 'at')
Occurred while linting /Users/josh/repos/turbo/docs/components/Authors.tsx:13
Rule: "@typescript-eslint/unbound-method"
    at checkMethod (/Users/josh/repos/turbo/node_modules/.pnpm/@typescript-eslint+eslint-plugin@6.14.0_@typescript-eslint+parser@6.14.0_eslint@8.55.0_typescript@4.9.5/node_modules/@typescript-eslint/eslint-plugin/dist/rules/unbound-method.js:222:48)
    at checkMethodAndReport (/Users/josh/repos/turbo/node_modules/.pnpm/@typescript-eslint+eslint-plugin@6.14.0_@typescript-eslint+parser@6.14.0_eslint@8.55.0_typescript@4.9.5/node_modules/@typescript-eslint/eslint-plugin/dist/rules/unbound-method.js:160:53)
    at MemberExpression (/Users/josh/repos/turbo/node_modules/.pnpm/@typescript-eslint+eslint-plugin@6.14.0_@typescript-eslint+parser@6.14.0_eslint@8.55.0_typescript@4.9.5/node_modules/@typescript-eslint/eslint-plugin/dist/rules/unbound-method.js:181:17)
    at ruleErrorHandler (/Users/josh/repos/turbo/node_modules/.pnpm/eslint@8.55.0/node_modules/eslint/lib/linter/linter.js:1091:28)
    at /Users/josh/repos/turbo/node_modules/.pnpm/eslint@8.55.0/node_modules/eslint/lib/linter/safe-emitter.js:45:58
    at Array.forEach (<anonymous>)
    at Object.emit (/Users/josh/repos/turbo/node_modules/.pnpm/eslint@8.55.0/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (/Users/josh/repos/turbo/node_modules/.pnpm/eslint@8.55.0/node_modules/eslint/lib/linter/node-event-generator.js:297:26)
    at NodeEventGenerator.applySelectors (/Users/josh/repos/turbo/node_modules/.pnpm/eslint@8.55.0/node_modules/eslint/lib/linter/node-event-generator.js:326:22)
    at NodeEventGenerator.enterNode (/Users/josh/repos/turbo/node_modules/.pnpm/eslint@8.55.0/node_modules/eslint/lib/linter/node-event-generator.js:340:14)

Coming from:

const firstParam = decl.parameters.at(0);

Logging just before the crash shows:

  • decl.getSourceFile().fileName: .../turbo/node_modules/.pnpm/typescript@5.3.3/node_modules/typescript/lib/lib.es5.d.ts
  • ts.SyntaxKind[decl.kind]: "MethodDeclaration"
  • decl.getText(): length: number

Very interesting that decl.parameters is undefined. The ts.MethodDeclaration type extends from SignatureDeclarationBase, which has a required readonly parameters: NodeArray<ParameterDeclaration>.

@JoshuaKGoldberg
Copy link
Member

Aha! It's a versioning issue. I:

  1. added "typescript": "5.3.3" in package.json's "overrides"
  2. ran pnpm install
  3. re-ran npx eslint docs/components/*

No crash.

Interesting that our tooling didn't report any complaint about a TypeScript version mismatch... I'm thinking it probably should.

@anthonyshew
Copy link
Author

0% surprised that this was on my end. 😄 Yes, definitely would have loved a warning or error with some help there. I was savvy enough to adjust our TS verison in the root thinking it might have been resolving there but wasn't smart enough to dedupe all of them.

I'm unblocked! Feel free to close - unless you want something to track version mismatch warning, of course!

Thanks for the prompt help, @JoshuaKGoldberg !

anthonyshew pushed a commit to vercel/turborepo that referenced this issue Dec 15, 2023
### Description

Throwing up this draft PR to show my suggested fix: deduplicating
TypeScript versions. No worries if you end up doing it yourself. I don't
have a fully working turbo repository setup locally to verify these
changes. 😄

See investigation in
typescript-eslint/typescript-eslint#8075.
There were multiple TypeScript versions, so enum constants used by
typescript-eslint rules weren't set to the values those rules expected.

### Testing Instructions

```shell
pnpm i
npx eslint docs/components/*
```
@bradzacher
Copy link
Member

@JoshuaKGoldberg

The reason there was no error was because we are supposed to support 4.7
This shouldn't crash - so it's still a bug in our tooling.

@bradzacher bradzacher added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin accepting prs Go ahead, send a pull request that resolves this issue and removed triage Waiting for team members to take a look labels Dec 16, 2023
@lsmurray

This comment has been minimized.

@bradzacher

This comment has been minimized.

@Josh-Cena
Copy link
Member

I haven't seen this error again and this issue doesn't provide an easy way to reproduce. Assuming this is not relevant anymore

@github-actions github-actions bot added the locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. label Jun 12, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

No branches or pull requests

5 participants