Skip to content

fix: use strip-json-comments instead of fragile regex for JSONC parsing - #174

Open
YoinkingFishy wants to merge 1 commit into
firecrawl:mainfrom
YoinkingFishy:fix/remove-json-comments-regex
Open

fix: use strip-json-comments instead of fragile regex for JSONC parsing#174
YoinkingFishy wants to merge 1 commit into
firecrawl:mainfrom
YoinkingFishy:fix/remove-json-comments-regex

Conversation

@YoinkingFishy

@YoinkingFishy YoinkingFishy commented Jul 30, 2026

Copy link
Copy Markdown

Fixes firecrawl/firecrawl#3976

Problem

The hand-rolled removeJsonComments() regex /(^|[^:\\\\])\/\/.*$/gm strips everything after // on any line where // isn't preceded by : or \. This incorrectly mutates JSON string values containing // (e.g. shell commands, file paths), producing invalid JSON that causes Claude Code settings to be silently skipped.

Change

  • Replaced removeJsonComments() with the strip-json-comments library which properly handles string context when stripping comments
  • Updated package.json to add strip-json-comments@^5.0.0 as a dependency

Verification

The function is used in a try/catch around JSON.parse() — the change preserves the original error-handling behavior but makes parsing succeed for JSONC files where // appears inside string values.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.


Summary by cubic

Replaced fragile regex-based JSONC stripping with strip-json-comments to correctly parse configs when // appears inside strings, preventing valid Claude Code settings from being skipped. Fixes firecrawl/firecrawl#3976.

  • Bug Fixes

    • Use strip-json-comments for comment removal, preserving string contents so JSON.parse succeeds on JSONC.
  • Dependencies

    • Added strip-json-comments@^5.0.0.

Written for commit 7399c68. Summary will update on new commits.

Review in cubic

The hand-rolled removeJsonComments() regex strips // content even when it
appears inside JSON string values (e.g. shell commands, file paths with
// in them), causing valid settings.json files to be silently skipped.

Replace with the strip-json-comments library which properly handles
string context when stripping comments from JSONC content.

Fixes firecrawl/firecrawl#3976

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 2 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="package.json">

<violation number="1" location="package.json:77">
P0: The added dependency strip-json-comments@^5.0.0 is ESM-only ("type": "module"), but the project compiles TypeScript to CommonJS ("module": "commonjs" in tsconfig.json). At runtime, require('strip-json-comments') will throw ERR_REQUIRE_ESM on any code path that calls stripJsonComments() — such as parsing Claude Code settings.json. Use strip-json-comments@^3.1.1 instead, which is published as CommonJS (no "type": "module") and compatible with the project's current module system.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

Comment thread package.json
"@inquirer/prompts": "^8.2.1",
"commander": "^14.0.2",
"firecrawl": "4.24.0",
"strip-json-comments": "^5.0.0",

@cubic-dev-ai cubic-dev-ai Bot Jul 30, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P0: The added dependency strip-json-comments@^5.0.0 is ESM-only ("type": "module"), but the project compiles TypeScript to CommonJS ("module": "commonjs" in tsconfig.json). At runtime, require('strip-json-comments') will throw ERR_REQUIRE_ESM on any code path that calls stripJsonComments() — such as parsing Claude Code settings.json. Use strip-json-comments@^3.1.1 instead, which is published as CommonJS (no "type": "module") and compatible with the project's current module system.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At package.json, line 77:

<comment>The added dependency strip-json-comments@^5.0.0 is ESM-only ("type": "module"), but the project compiles TypeScript to CommonJS ("module": "commonjs" in tsconfig.json). At runtime, require('strip-json-comments') will throw ERR_REQUIRE_ESM on any code path that calls stripJsonComments() — such as parsing Claude Code settings.json. Use strip-json-comments@^3.1.1 instead, which is published as CommonJS (no "type": "module") and compatible with the project's current module system.</comment>

<file context>
@@ -74,6 +74,7 @@
     "@inquirer/prompts": "^8.2.1",
     "commander": "^14.0.2",
     "firecrawl": "4.24.0",
+    "strip-json-comments": "^5.0.0",
     "yaml": "^2.9.0",
     "zod-to-json-schema": "3.24.6"
</file context>
Fix with cubic

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 this pull request may close these issues.

make default: removeJsonComments regex strips // inside JSON string values, causing settings.json parse failure

1 participant