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

TypeError: Converting circular structure to JSON #96

Open
lencioni opened this issue Jul 1, 2020 · 5 comments · May be fixed by #138
Open

TypeError: Converting circular structure to JSON #96

lencioni opened this issue Jul 1, 2020 · 5 comments · May be fixed by #138

Comments

@lencioni
Copy link
Contributor

lencioni commented Jul 1, 2020

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
Copy link
Contributor Author

lencioni commented Jul 2, 2020

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
Copy link
Contributor Author

lencioni commented Jul 2, 2020

Upstream bug report: facebook/react#19243

@SimenB
Copy link
Member

SimenB commented Jul 4, 2020

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

alunny added a commit to alunny/jest-runner-eslint that referenced this issue May 11, 2022
@alunny alunny linked a pull request May 11, 2022 that will close this issue
@giorgio-zamparelli
Copy link

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

@SimenB SimenB linked a pull request Aug 25, 2022 that will close this issue
@danielo515
Copy link

danielo515 commented Nov 28, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants