Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lint-staged fails when cwd package.json is missing a version field #1043

Closed
coalman opened this issue Nov 13, 2021 · 2 comments
Closed

lint-staged fails when cwd package.json is missing a version field #1043

coalman opened this issue Nov 13, 2021 · 2 comments

Comments

@coalman
Copy link
Contributor

coalman commented Nov 13, 2021

Description

This looks like a regression in v12.0.0

Using lint-staged in a project with a package.json file that is missing a version field causes lint-staged to crash. It shouldn't.

Steps to reproduce

You can create a new project with a package.json file that is missing a version field and install lint-staged locally in the project. Run:

$ npx lint-staged

It will crash with an error like this (I replaced part of the file path with "{repo}"):

file:///{repo}/node_modules/lint-staged/bin/lint-staged.js:25
  .option('--allow-empty', 'allow empty commits when tasks revert all staged changes', false)
  ^

TypeError: Cannot read properties of undefined (reading 'option')
    at file:///{repo}/node_modules/lint-staged/bin/lint-staged.js:25:3
    at ModuleJob.run (node:internal/modules/esm/module_job:185:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:281:24)
    at async loadESM (node:internal/process/esm_loader:88:5)
    at async handleMainPromise (node:internal/modules/run_main:65:12)

Adding a version number to "{repo}/package.json" fixes this.

Debug Logs

I tried running in debug mode, but it didn't add anything else to the error printed above.

Environment

  • OS: macOS Big Sur
  • Node.js: 16.13.0
  • lint-staged: v12.0.0

Edit: I think I see the issue. Working on a PR atm.

iiroj pushed a commit that referenced this issue Nov 13, 2021
…kage.json in cwd (#1043) (#1044)

If the package.json did not have a version number, it would cause lint-staged to crash.
@coalman
Copy link
Contributor Author

coalman commented Nov 13, 2021

v12.0.1 fixes this for me (and prints correct version number).

@coalman coalman closed this as completed Nov 13, 2021
@iiroj
Copy link
Member

iiroj commented Nov 13, 2021

Thanks a lot for noticing, and the quick fix, @coalman!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants