typicode / husky

Git hooks made easy 🐶 woof!
https://typicode.github.io/husky
MIT License
31.75k stars 999 forks source link

fix: add scripts field if not present #1338

Closed chalkygames123 closed 4 months ago

chalkygames123 commented 4 months ago

Fixed an error that occurs on installation if the scripts field is not present in package.json.

$ npx husky init
Need to install the following packages:
husky@9.0.1
Ok to proceed? (y) 
file:///Users/takuya/.npm/_npx/0d92fdd791cc1044/node_modules/husky/bin.js:10
  d.scripts.prepare = 'husky'
                    ^

TypeError: Cannot set properties of undefined (setting 'prepare')
    at file:///Users/takuya/.npm/_npx/0d92fdd791cc1044/node_modules/husky/bin.js:10:21
    at ModuleJob.run (node:internal/modules/esm/module_job:218:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:329:24)
    at async loadESM (node:internal/process/esm_loader:28:7)
    at async handleMainPromise (node:internal/modules/run_main:113:12)

Node.js v21.4.0
typicode commented 4 months ago

Thank you