Fix TypeError: data.find is not a function on first startup after npx karin init #564
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
When running
npx karin initto initialize Karin for the first time, the application would crash with the error:This prevented users from successfully completing the initial setup, though restarting the terminal would make it work on subsequent attempts.
Root Cause
The issue was in
packages/cli-Internal/src/init.tsat line 360, where configuration files were being merged during initialization:When both
groups.jsonandprivates.json(which are arrays) were merged using the object spread operator, they were inadvertently converted from arrays into objects with numeric keys:Since objects don't have the
.find()method, subsequent code that tried to calldata.find(item => item.key === 'global')would fail with the TypeError.Solution
1. Fixed Array Merging in init.ts
Added proper type detection to preserve array types during config file merging:
2. Updated Default Configuration Files
Fixed
packages/core/default/config/privates.jsonandgroups.jsonto include:"global"key entry (required by the format functions)"inherit": trueproperty on all entries (required by TypeScript interfaces)memberEnable,memberDisable)3. Added Defensive Checks
Enhanced the
format()functions in bothprivates.tsandgroups.tsto gracefully handle edge cases:Testing
Verified the fix with a comprehensive test script that confirms:
This fix ensures that first-time initialization with
npx karin initwill complete successfully without errors.Fixes #[issue_number]
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
registry.npmmirror.comnode /home/REDACTED/.npm/_npx/4876f32048baf8ac/node_modules/.bin/prebuild-install -r napi --pkg_version=5.1.7 --pkg_name=sqlite3(dns block)node /home/REDACTED/.npm/_npx/c65dbefa27d408e0/node_modules/.bin/prebuild-install -r node --pkg_version=0.12.0 --pkg_name=node-pty-prebuilt-multiarch(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
Fixes #527
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.