Skip to content

Fix TypeError when no package manager lock file exists#265

Merged
ryota-murakami merged 1 commit intomainfrom
copilot/fix-typeerror-invalid-arg-type
Nov 6, 2025
Merged

Fix TypeError when no package manager lock file exists#265
ryota-murakami merged 1 commit intomainfrom
copilot/fix-typeerror-invalid-arg-type

Conversation

Copy link
Contributor

Copilot AI commented Nov 6, 2025

Users running npx prettier-husky-lint-staged-installer in projects without package-lock.json, pnpm-lock.yaml, or bun.lockb encounter:

TypeError [ERR_INVALID_ARG_TYPE]: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received undefined

Analysis

Published version 1.3.1 lacks process.exit(0) in the else block when no supported lock file is found. Script continues executing with precommitFileBody undefined, causing TypeError when writing to .husky/pre-commit.

Fix

Status: Already fixed in repository code (commit 81f9488), not yet published to npm.

Line 42 of bin/cli.js includes the missing process.exit(0):

} else {
  p.stop()
  p.message('This project only support npm/pnpm/bun project.')
  outro('Finished.')
  process.exit(0)  // Prevents undefined precommitFileBody usage
}

Additionally, the code uses promise-based fs operations (node:fs/promises) instead of callback-based operations for proper async handling.

Next Step

Publish version 1.3.2+ to npm to deploy the fix.

Original prompt

This section details on the original issue you should resolve

<issue_title>TypeError [ERR_INVALID_ARG_TYPE]: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received undefined</issue_title>
<issue_description>~/l/create-web-site (main|↑1|✚3) $ npx prettier-husky-lint-staged-installer
┌ Installing via husky, prettier, lint-staged...



└ Finished.


┌ Configration...



└ You're all set!🎉

node:internal/errors:540
throw error;
^

TypeError [ERR_INVALID_ARG_TYPE]: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received undefined
at writeFile (node:fs:2368:5)
at file:///Users/ryotamurakami/.npm/_npx/a8a5225a7dd30b1e/node_modules/prettier-husky-lint-staged-installer/bin/cli.js:65:3
at FSReqCallback.readFileAfterClose [as oncomplete] (node:internal/fs/read/context:68:3) {
code: 'ERR_INVALID_ARG_TYPE'</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Fix TypeError for invalid 'data' argument Fix TypeError when no package manager lock file exists Nov 6, 2025
Copilot AI requested a review from ryota-murakami November 6, 2025 01:07
@ryota-murakami ryota-murakami marked this pull request as ready for review November 6, 2025 01:54
@ryota-murakami ryota-murakami merged commit ee27f11 into main Nov 6, 2025
7 checks passed
@ryota-murakami ryota-murakami deleted the copilot/fix-typeerror-invalid-arg-type branch November 6, 2025 01:54
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.

TypeError [ERR_INVALID_ARG_TYPE]: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received undefined

2 participants