jest-community / jest-runner-eslint

An ESLint runner for Jest
MIT License
479 stars 45 forks source link

TypeError: Converting circular structure to JSON #96

Open lencioni opened 4 years ago

lencioni commented 4 years ago

I've been looking at our logs in CI and I've noticed the following error pop up a bunch of times:

TypeError: Converting circular structure to JSON
    at JSON.stringify (<anonymous>)
    at process.target._send (internal/child_process.js:735:23)
    at process.target.send (internal/child_process.js:634:19)
    at reportError (/path/to/repo/node_modules/jest-runner-eslint/node_modules/jest-worker/build/workers/processChild.js:103:11)
    at reportClientError (/path/to/repo/node_modules/jest-runner-eslint/node_modules/jest-worker/build/workers/processChild.js:87:10)
    at execFunction (/path/to/repo/node_modules/jest-runner-eslint/node_modules/jest-worker/build/workers/processChild.js:157:5)
    at execHelper (/path/to/repo/node_modules/jest-runner-eslint/node_modules/jest-worker/build/workers/processChild.js:139:5)
    at execMethod (/path/to/repo/node_modules/jest-runner-eslint/node_modules/jest-worker/build/workers/processChild.js:143:5)
    at process.on.request (/path/to/repo/node_modules/jest-runner-eslint/node_modules/jest-worker/build/workers/processChild.js:64:7)
    at process.emit (events.js:198:13)

jest-runner-eslint 0.9.0

I believe that nested jest-worker version is 24.9.0.

Based on this stack trace I'm not really sure where this might be coming from or how I might reduce it to a minimal repro case. Any ideas or suggestions of where to start?

lencioni commented 4 years ago

I've narrowed it down a bit more, at least for some of these. This issue seems to arise in a handful of files when I am updating eslint-plugin-react-hooks from 2.5.1 to 4.0.5. When I run eslint without the jest runner, I get a more useful error here:

TypeError: Cannot read property 'references' of undefined
Occurred while linting /path/to/repo/file.ts:102
    at /path/to/repo/node_modules/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.development.js:1681:23
    at Set.forEach (<anonymous>)
    at visitFunctionWithDependencies (/path/to/repo/node_modules/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.development.js:1672:29)
    at visitCallExpression (/path/to/repo/node_modules/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.development.js:886:19)
    at /path/to/repo/node_modules/eslint/lib/linter/safe-emitter.js:45:58
    at Array.forEach (<anonymous>)
    at Object.emit (/path/to/repo/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (/path/to/repo/node_modules/eslint/lib/linter/node-event-generator.js:254:26)
    at NodeEventGenerator.applySelectors (/path/to/repo/node_modules/eslint/lib/linter/node-event-generator.js:283:22)
    at NodeEventGenerator.enterNode (/path/to/repo/node_modules/eslint/lib/linter/node-event-generator.js:297:14)

In this particular case, I was able to reproduce it with this file:

import React, { useEffect, useContext } from 'react';

export const Repro = (props) => {
  const fooContext = useContext(foo);

  const bar = () => {
    baz({
      pizza: fooContext.pizza,
      pasta: fooContext?.pasta?.sauce,
    });
  };

  useEffect(bar, []);

  return <div />;
};

If I change this file in a number of ways (e.g. removing the pizza, removing useContext, or removing one of the optional chaining operators), it doesn't cause this error. This is almost certainly a bug in the rule (I'll file an issue upstream), but it seems that jest-runner-eslint should be able to handle this more clearly instead of adding an additional failure on top of it that obscures the root cause.

lencioni commented 4 years ago

Upstream bug report: https://github.com/facebook/react/issues/19243

SimenB commented 4 years ago

@lencioni do you think we can do anything to avoid making the error worse than when running "plain" eslint?

giorgio-zamparelli commented 2 years ago

I've encountered the error TypeError: Converting circular structure to JSON again while updating from eslint 7.32.0 to 8.20.0 with eslint-plugin-react-hooks 4.2.0 Updating to latest stable eslint-plugin-react-hooks 4.6.0 fixed the problem

danielo515 commented 9 months ago

I am not using any of the mentioned libraries, just plain eslint and jest, but i'm getting this problem within the jest-worker