eslint-plugin-prettier icon indicating copy to clipboard operation
eslint-plugin-prettier copied to clipboard

Random Eslint failure since upgrading to v5.2.1

Open andrewbrennanfr opened this issue 1 year ago • 17 comments

What version of eslint are you using? 8.57.0 What version of prettier are you using? Not installed as a dep of our project, but npx prettier --version returns 3.2.5 What version of eslint-plugin-prettier are you using? 5.2.1 Please paste any applicable config files that you're using (e.g. .prettierrc or .eslintrc files)

What source code are you linting? .vue/.ts What did you expect to happen? For the linter to succeed What actually happened? In our the CI build, we have (seemingly random - as repeated runs causes it to pass) errors during linting. Local runs of the linter do not fail, only in the CI.

Our error looks something similar to this (I've removed some details to make it more readable) & mentions synckit which was upgraded in the latest version of eslint-plugin-prettier.

Oops! Something went wrong! :(

ESLint: 8.57.0

TypeError: Cannot read properties of undefined (reading 'message')
Occurred while linting /path/to/file.ts:2
Rule: "prettier/prettier"
    at syncFn (/....../node_modules/.pnpm/[email protected]/node_modules/synckit/lib/index.cjs:362:59)
    at Program (/....../node_modules/.pnpm/[email protected][email protected][email protected][email protected][email protected]/node_modules/eslint-plugin-prettier/eslint-plugin-prettier.js:191:32)
    at ruleErrorHandler (/....../node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/linter.js:1076:28)
    at /....../node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/safe-emitter.js:45:58
    at Array.forEach (<anonymous>)
    at Object.emit (/....../node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (/....../node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/node-event-generator.js:297:26)
    at NodeEventGenerator.applySelectors (/....../node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/node-event-generator.js:326:22)
    at NodeEventGenerator.enterNode (/....../node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/node-event-generator.js:340:14)
    at CodePathAnalyzer.enterNode (/....../node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/code-path-analysis/code-path-analyzer.js:803:23)

Downgrading to the previous version we had installed 5.1.3, looks to fix the issue.

andrewbrennanfr avatar Jul 24 '24 10:07 andrewbrennanfr

Please provide a runnable reproduction.

JounQin avatar Jul 25 '24 11:07 JounQin

@JounQin I don't have one right now - because I can only get it to fail on our CI build.

I downgraded last week & re-upgraded this week - hoping it was just random. But to no avail.

But judging from the 👍 on my report - seems like I might not be the only one. 👀 @dmeyer-pfg do you have a reproducible case to share?

andrewbrennanfr avatar Jul 31 '24 12:07 andrewbrennanfr

Just a heads up that this is still an issue for us ☝️ And judging by the thumbs up - we aren't the only ones.

andrewbrennanfr avatar Aug 26 '24 08:08 andrewbrennanfr

The thumbs up help nothing, we need a reproduction to debug.

JounQin avatar Aug 26 '24 09:08 JounQin

We're having the same issue, running next lint inside github actions. Works sometimes, fails with this error in others. Not yet able to repro in a consistent way, but will circle back if we manage.

Given that @andrewbrennanfr 's stack trace appears to be erroring at https://github.com/fmal/synckit/blob/bd607595c13c133df7544bb5281fd2e29ddc52ba/src/index.ts#L547, it looks like receiveMessageOnPort is returning undefined in some cases?

This is happening on node v20.16.0 which might be relevant given this PR in the release https://github.com/un-ts/synckit/pull/175.

@andrewbrennanfr which version of node are you seeing the error in?

dan-goswag avatar Aug 26 '24 15:08 dan-goswag

Maybe you can use resolutions(yarn)/overrides(npm/pnpm) synckit: "0.9.0" to confirm whether https://github.com/un-ts/synckit/pull/175 is related?

JounQin avatar Aug 26 '24 16:08 JounQin

The thumbs up help nothing, we need a reproduction to debug.

As I said, it only happens on our CI, so I don't have an example to share.

We're having the same issue, running next lint inside github actions.

We don't use next, but we do use github actions. So somewhat similar.

which version of node are you seeing the error in?

Node 20.x (~20.11.0) - but I run the same node version locally it has never failed locally.

Maybe you can use resolutions(yarn)/overrides(npm/pnpm) synckit: "0.9.0" to confirm whether https://github.com/un-ts/synckit/pull/175 is related?

This doesn't work at 0.9.0 (passed three times & but failed at least once for me) - but pinning at 0.8.8 does work (ran several times without failure for what it's worth).

It's hard to know, because it's somewhat flaky to reproduce.

But I can say that running the linter on github actions, with node20.11 has at least intermittent errors.

andrewbrennanfr avatar Aug 27 '24 08:08 andrewbrennanfr

Can confirm the same error happening in CI for us (seemlingy random):


ESLint: 9.9.0

TypeError: Cannot read properties of undefined (reading 'message')
Occurred while linting /home/runner/work/cdm/cdm/shared/utils/index.ts:1
Rule: "prettier/prettier"
    at syncFn (/home/runner/work/cdm/cdm/node_modules/synckit/lib/index.cjs:362:59)
    at Program (/home/runner/work/cdm/cdm/node_modules/eslint-plugin-prettier/eslint-plugin-prettier.js:191:32)
    at ruleErrorHandler (/home/runner/work/cdm/cdm/node_modules/eslint/lib/linter/linter.js:1124:48)
    at /home/runner/work/cdm/cdm/node_modules/eslint/lib/linter/safe-emitter.js:45:58
    at Array.forEach (<anonymous>)
    at Object.emit (/home/runner/work/cdm/cdm/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (/home/runner/work/cdm/cdm/node_modules/eslint/lib/linter/node-event-generator.js:297:26)
    at NodeEventGenerator.applySelectors (/home/runner/work/cdm/cdm/node_modules/eslint/lib/linter/node-event-generator.js:326:22)
    at NodeEventGenerator.enterNode (/home/runner/work/cdm/cdm/node_modules/eslint/lib/linter/node-event-generator.js:337:14)
    at runRules (/home/runner/work/cdm/cdm/node_modules/eslint/lib/linter/linter.js:1[16](https://github.com/fadi-nextgen-shop/cdm/actions/runs/10578074065/job/29307463664#step:10:17)8:40)

Packages: "eslint": "9.9.0", "eslint-config-prettier": "9.1.0", "eslint-plugin-prettier": "5.2.1",

Node 20.12.0 and yarn 4.1.1 but no pnp only regular node-modules Also using github actions running ubuntu-latest default runners

MDSLKTR avatar Aug 27 '24 12:08 MDSLKTR

Can confirm pinned 0.9.0 has failed for me. I have not yet managed to make pinned 0.8.8 fail.

dan-goswag avatar Aug 28 '24 13:08 dan-goswag

Here the error is intermittent, sometimes it occurs in the pipeline, sometimes it doesn't.

Packages:

"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.2.1",

Node: v20.16.0 Yarn: v1.22.22 Env: Github Actions

Error:


TypeError: Cannot read properties of undefined (reading 'message')
Oops! Something went wrong! :(

    ESLint: 8.56.0
    
    TypeError: Cannot read properties of undefined (reading 'message')
    Occurred while linting /home/runner/work/project/src/services/model/ExploreItem.ts:1
    Rule: "prettier/prettier"
        at syncFn (/home/runner/work/project/node_modules/synckit/lib/index.cjs:362:59)
        at Program (/home/runner/work/project/node_modules/eslint-plugin-prettier/eslint-plugin-prettier.js:191:32)
        at ruleErrorHandler (/home/runner/work/project/node_modules/eslint/lib/linter/linter.js:1076:28)
        at /home/runner/work/project/node_modules/eslint/lib/linter/safe-emitter.js:45:58
        at Array.forEach (<anonymous>)
        at Object.emit (/home/runner/work/project/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
        at NodeEventGenerator.applySelector (/home/runner/work/project/node_modules/eslint/lib/linter/node-event-generator.js:297:26)
        at NodeEventGenerator.applySelectors (/home/runner/work/project/node_modules/eslint/lib/linter/node-event-generator.js:326:22)
        at NodeEventGenerator.enterNode (/home/runner/work/project/node_modules/eslint/lib/linter/node-event-generator.js:340:14)
        at CodePathAnalyzer.enterNode (/home/runner/work/project/node_modules/eslint/lib/linter/code-path-analysis/code-path-analyzer.js:803:23)
    error Command failed with exit code 2.

joaocrleite avatar Aug 28 '24 18:08 joaocrleite

Here's mine. Seems to only affect the CI environment:

"eslint": "8.57.0",
"eslint-config-prettier": "9.1.0",
"eslint-plugin-prettier": "5.2.1",
"prettier": "3.3.3"
Oops! Something went wrong! :(

ESLint: 8.57.0

TypeError: Cannot read properties of undefined (reading 'message')
Occurred while linting /home/runner/work/project/src/workers/scoring/scoring.triggers.ts:1
Rule: "prettier/prettier"
    at syncFn (/home/runner/work/project/node_modules/synckit/lib/index.cjs:362:59)
    at Program (/home/runner/work/project/node_modules/eslint-plugin-prettier/eslint-plugin-prettier.js:191:32)
    at ruleErrorHandler (/home/runner/work/project/node_modules/eslint/lib/linter/linter.js:1076:28)
    at /home/runner/work/project/node_modules/eslint/lib/linter/safe-emitter.js:45:[58](https://github.com/StudentFinance/mydra-api/actions/runs/10671073917/job/29576215739?pr=980#step:4:59)
    at Array.forEach (<anonymous>)
    at Object.emit (/home/runner/work/project/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (/home/runner/work/project/node_modules/eslint/lib/linter/node-event-generator.js:297:26)
    at NodeEventGenerator.applySelectors (/home/runner/work/project/node_modules/eslint/lib/linter/node-event-generator.js:326:22)
    at NodeEventGenerator.enterNode (/home/runner/work/project/node_modules/eslint/lib/linter/node-event-generator.js:340:14)
    at CodePathAnalyzer.enterNode (/home/runner/work/project/node_modules/eslint/lib/linter/code-path-analysis/code-path-analyzer.js:803:23)

felipelube avatar Sep 02 '24 18:09 felipelube

Looks like the error could be in Synckit: https://github.com/un-ts/synckit/blob/main/src/index.ts#L548

Maybe sometimes receives messages that aren't objects with a message property.

What are those messages and where are they coming from?

dylang avatar Sep 05 '24 15:09 dylang

Ran into this issue today as well. Using overrides with "synckit": "0.8.8" does seem to work for me as well. Thanks @JounQin and @andrewbrennanfr for the temporary workaround.

 "overrides": {
    "eslint-plugin-prettier": {
      "synckit": "0.8.8"
    }
  },

greypants avatar Oct 08 '24 18:10 greypants

Hi 👋 Just an update here (as I opened this issue).

In the end we've removed this plugin from our stack & gone back to using Prettier as a standalone tool.

For a while we've wanted to just manage the code formatting ourselves with Prettier. And after hitting this issue - it pushed us to just go back to using Prettier instead.

So I'll leave the issue open for others who face the problem. But on our side it's no longer a problem. 🙂

Thanks 👍

andrewbrennanfr avatar Oct 10 '24 13:10 andrewbrennanfr

From the error call stack, this is the line that is failing: https://github.com/un-ts/synckit/blob/42918e8b340b7b6466a5ba280b946b78735877b3/src/index.ts#L547 where receiveMessageOnPort(mainPort) is undefined

receiveMessageOnPort is a node function that may return undefined (when there is no message to receive), so this seems valid. If anyone could explain why synckit might call it at a time where there is no message and hence returns undefined that would be great, but all I can assume is that GitHub actions causes it to happen more frequently where local environments do not.

Therefore @JounQin it would be prudent to have a undefined check around these lines: https://github.com/un-ts/synckit/blob/42918e8b340b7b6466a5ba280b946b78735877b3/src/index.ts#L545-L547

- const { id, ...message } = (receiveMessageOnPort(mainPort) as { message: WorkerToMainMessage<R> }).message
+ const received = receiveMessageOnPort(mainPort) as { undefined | message?: WorkerToMainMessage<R> };
+ if (!received) {
+   // TODO: Handle undefined
+ } else {
+  // happy path
+  const { id, ...message } = received.message;

as well as maybe assess when this function could be called out of turn?


However, I see a PR has been merged 4 days ago pertaining to this code: https://github.com/un-ts/synckit/pull/184

@JounQin could you comment if this could impact/help resolve this issue based on the stack trace? Perhaps @jedlikowski could help here also?


One last thing around pinning 0.8.8:

Can confirm pinned 0.9.0 has failed for me. I have not yet managed to make pinned 0.8.8 fail.

If 0.9.0 fails and 0.8.8 is succeeding, there's not too much that has changed in synckit since then: un-ts/synckit@v0.8.8...v0.9.0#diff-a2a171449d

Looking at that diff I can't see any reason there would be a regression in those changes.

JamesBurnside avatar Oct 11 '24 03:10 JamesBurnside

If we can not determine which change impact the new random behavior, I don't think we can fix it confidentially.


Mostly it could be related to https://github.com/un-ts/synckit/pull/154

cc @onigoetz

Any idea?

JounQin avatar Oct 11 '24 03:10 JounQin

Hey @JamesBurnside, in the mentioned PR, I worked on gracefully handling tasks that timeout in the main process but still successfully finish in the worker process. My initial idea was to create a separate MessageChannel for execution of syncFn but I encountered the same problem as you mention here: no message received on port. I never investigated that in more depth as I found an even better alternative.

Just adding my perspective here :)

jedlikowski avatar Oct 16 '24 07:10 jedlikowski

I can shortly confirm that it is failing with the exact stacktrace only on github actions 1 out of maybe 30 runs. It's so hard to create a reproducible case.

Can-Sahin avatar Nov 18 '24 09:11 Can-Sahin

Hi all! Does this error still occurs recently? A GitHub repository showing case which I can debug with would be appreciated.

JounQin avatar Mar 10 '25 22:03 JounQin

It's possible that https://github.com/un-ts/synckit/pull/184 fixes it, but this repo is still using the previous version (the ^ doesn't work for 0.x.y versions).

dylang avatar Mar 10 '25 22:03 dylang

the ^ doesn't work for 0.x.y versions

@dylang Nope,^ works in this way, try yarn up -R synckit or pnpm up -r synckitfor example.

JounQin avatar Mar 11 '25 00:03 JounQin

We have a persistent reproduction now https://github.com/un-ts/synckit/pull/217

JounQin avatar Apr 01 '25 03:04 JounQin

Should be fixed in https://github.com/prettier/eslint-plugin-prettier/releases/tag/v5.4.1

JounQin avatar May 30 '25 03:05 JounQin