question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

nx tries to parse JSONC files as JSON which causes commands to fail

See original GitHub issue

I 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:open
  • Created a year ago
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
DesignByOnyxcommented, Aug 5, 2022

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”.

1reaction
DesignByOnyxcommented, Aug 2, 2022

I just ran into this issue too. They are using the jsonc-parser, which has an option for allowTrailingComma (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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found