''TypeError: Converting circular structure to JSON' in a Lerna workspace with CRA and Typescript
I have a Lerna Workspace with some packages and a webapp created with create-react-app using TypeScript.
When I try to add node-sass (needed for customizing ag-grid library themes, which I'm using in this project), I get the following error which I can't figure why it's happening:
TypeError: Converting circular structure to JSON
--> starting at object with constructor 'SourceFileObject'
| property 'statements' -> object with constructor 'Array'
| index 0 -> object with constructor 'NodeObject'
--- property 'parent' closes the circle
at JSON.stringify (<anonymous>)
at getBuildInfoText (path/to/project/packages/front/node_modules/typescript/lib/typescript.js:107932:21)
at emitBuildInfo (path/to/project/packages/front/node_modules/typescript/lib/typescript.js:107709:67)
at emitSourceFileOrBundle (path/to/project/packages/front/node_modules/typescript/lib/typescript.js:107674:13)
at forEachEmittedFile (path/to/project/packages/front/node_modules/typescript/lib/typescript.js:107416:28)
at Object.emitFiles (path/to/project/packages/front/node_modules/typescript/lib/typescript.js:107648:9)
at Object.emitBuildInfo (path/to/project/packages/front/node_modules/typescript/lib/typescript.js:114560:33)
at emitTsBuildInfoFileForBuilderProgram (path/to/project/packages/front/node_modules/fork-ts-checker-webpack-plugin/lib/typescript-reporter/reporter/TypeScriptReporter.js:86:25)
at path/to/project/packages/front/node_modules/fork-ts-checker-webpack-plugin/lib/typescript-reporter/reporter/TypeScriptReporter.js:295:37
at Object.afterProgramCreate (path/to/project/packages/front/node_modules/fork-ts-checker-webpack-plugin/lib/typescript-reporter/reporter/ControlledWatchCompilerHost.js:15:17)
Due to it being a private project, I can't provide a snippet with the code.
Thanks in advance for any clue on how to solve a problem like this.
Solution 1:[1]
I encountered this issue while upgrading a project to React 18.1.0
. In my case, upgrading Typescript to version 4.6.4
(the latest version at the time of writing) fixed it.
(I noticed the error message was coming from typescript-reporter
, which was the clue I needed to upgrade Typescript.)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Olly Hodgson |