nx tries to parse JSONC files as JSON which causes commands to fail
See original GitHub issueI created a “hello-world”-style NX repository using the following command:
npx create-nx-workspace isaacscript --preset=ts
After that, the only modification I made was to add more content to the extensions.json file.
After that, I ran the following command:
nx generate @nrwl/js:library --name=isaac-typescript-definitions --buildable --publishable --importPath="isaac-typescript-definitions"
It fails, with the following error message:
Cannot parse .vscode/extensions.json: ValueExpected in JSON at position 440
The “extensions.json” file is a JSONC file. JSONC is a format that supports comments and trailing commas. Thus, I believe that the error message is related to NX is trying to parse the JSONC file as a JSON file.
Since it is common for “extensions.json”, “settings.json”, and so on to contain JSONC features, this bug should be fixed!
Issue Analytics
- State:
- Created a year ago
- Comments:11 (3 by maintainers)
Top Results From Across the Web
npm "failed to parse json" - Stack Overflow
I solved the issue using below steps: Delete node_modules folder. Delete package-lock.json file. Run npm install.
Read more >SyntaxError: JSON.parse: bad parsing - JavaScript | MDN
SyntaxError: JSON.parse: bad parsing. The JavaScript exceptions thrown by JSON.parse() occur when string failed to be parsed as JSON.
Read more >jsonc-parser - npm
This node module provides a scanner and fault tolerant parser that can process JSONC but is also useful for standard JSON. the scanner...
Read more >MalformedJSONException: Resolving JSON Parsing Errors
json file directly, as they have a very specific format and one minor error will cause the entire file to become invalid. Solution....
Read more >How to parse JSON with C# | Teach Me Tech - YouTube
In this video Jeremy Morgan shows you how to read and parse a JSON file in C#. You'll learn how to: open the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
What sucks about this issue is that you run into very early. I had just set up my Nx workspace, made a couple changes to migrate existing/working tsconfigs, and then tried to run my first Nx command, and it failed with a really obscure error (see OP). When I visited the file, there were no visible errors (my editor shows errors in tsconfigs). This was not a pleasant “first taste” of Nx, and many others are likely to run into it. It’s an important issue because it affects new adopters of Nx, especially since Nx sells itself as “works with any project”.
I just ran into this issue too. They are using the
jsonc-parser
, which has an option forallowTrailingComma
(I don’t think jsonc allows trailing commas by default). The options are passed as the 3rd parameter here:https://github.com/nrwl/nx/blob/master/packages/nx/src/utils/json.ts#L49
It would be nice if trailing commas were allowed by default, especially when reading tsconfig files.