Skip to content

husky init fails when package.json does not have scripts #1342

@julien-f

Description

@julien-f

Troubleshoot

If you're migrating from husky 4, see:
https://typicode.github.io/husky/migrating-from-v4.html

Context

The error:

$ echo '{}' > package.json
$ npx husky init
Need to install the following packages:
husky@9.0.2
Ok to proceed? (y) y
file:///home/julien.fontanet/.npm/_npx/0d92fdd791cc1044/node_modules/husky/bin.js:10
  d.scripts.prepare = 'husky'
                    ^

TypeError: Cannot set properties of undefined (setting 'prepare')
    at file:///home/julien.fontanet/.npm/_npx/0d92fdd791cc1044/node_modules/husky/bin.js:10:21
    at ModuleJob.run (node:internal/modules/esm/module_job:195:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:336:24)
    at async loadESM (node:internal/process/esm_loader:34:7)
    at async handleMainPromise (node:internal/modules/run_main:106:12)

Node.js v18.19.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions