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

v11.2.4 is broken for config .lintstagedrc #1032

Closed
9jaGuy opened this issue Oct 24, 2021 · 29 comments · Fixed by #1033 or #981
Closed

v11.2.4 is broken for config .lintstagedrc #1032

9jaGuy opened this issue Oct 24, 2021 · 29 comments · Fixed by #1033 or #981

Comments

@9jaGuy
Copy link

9jaGuy commented Oct 24, 2021

Description

Steps to reproduce

  • upgrade to v11.2.4, and run npx lint-staged
  • nothing happens, it starts working after downgrading to v11.2.3

Environment

  • OS: Windows
  • Node.js: v14.17.6
  • lint-staged: v11.2.4
@iiroj
Copy link
Member

iiroj commented Oct 24, 2021

Please post your debug logs from npx lint-staged --debug.

@9jaGuy
Copy link
Author

9jaGuy commented Oct 24, 2021

Sure, I can downgrade and try again but I don't remember seeing anything in the log.

kinda what I meant by nothing happens

@9jaGuy
Copy link
Author

9jaGuy commented Oct 24, 2021

image

@w3nda
Copy link

w3nda commented Oct 24, 2021

I'm having something similar on unix.
lint-staged using husky is suddenly failing, no error, no debug.

EDIT

  • Using a macbook on macOS Big Sur 11.6
  • Using husky and lint staged on pre-commit, this is suddenly failing

@iiroj
Copy link
Member

iiroj commented Oct 24, 2021

Probably related to this: #981.

Let me open a revert PR.

@iiroj
Copy link
Member

iiroj commented Oct 24, 2021

Hmm, I cannot reproduce this myself on macOS 11.6.

~/git/iiro.fi master*
❯ npx lint-staged       
→ No staged files match any configured task.

~/git/iiro.fi master*
❯ npx lint-staged --version
11.2.4

~/git/iiro.fi master*
❯ npx lint-staged          
✔ Preparing...
⚠ Running tasks...
  ↓ No staged files match *.{js,jsx} [SKIPPED]
  ❯ Running tasks for *.{ts,tsx}
    ✖ eslint --ext .ts,.tsx -- [FAILED]
↓ Skipped because of errors from tasks. [SKIPPED]
✔ Reverting to original state because of errors...
✔ Cleaning up...

✖ eslint --ext .ts,.tsx --:

/Users/iiro/git/iiro.fi/site/src/index.tsx
  5:1  error  Delete `⏎⏎⏎`  prettier/prettier

✖ 1 problem (1 error, 0 warnings)
  1 error and 0 warnings potentially fixable with the `--fix` option.

Can you try if lint-staged --help or lint-staged --version work?

@w3nda
Copy link

w3nda commented Oct 24, 2021

Yes both are working, I can see the failure when running

yarn lint-staged

image

And this has worked until v11.2.4

@koshic
Copy link

koshic commented Oct 24, 2021

Have the same issue with 11.2.4 - exit 1 without any output. maxOS 11.6, yarn 3.0.2

--version & --help work as expected

@iiroj
Copy link
Member

iiroj commented Oct 24, 2021

@w3nda or @VladimirGrenaderov, can you try editing lint-staged? directly in your project via node_modules to add some debug messages?

So edit this file node_modules/lint-staged/lib/index.js and add:

+++ try {
      const resolved = configObject
          ? { config: configObject, filepath: '(input)' }
          : await loadConfig(configPath)
+++ } catch (error) {
+++     console.error(error)
+++     process.exit(1)
+++   }

This might indicate if the bug is indeed with lilconfig.

@w3nda
Copy link

w3nda commented Oct 24, 2021

@iiroj yes, I am getting this error

$ /Users/wenda/apps/acs-sc-web-platform/node_modules/.bin/lint-staged
TypeError: Cannot read property 'load' of undefined
    at jsYamlLoad (/Users/wenda/apps/acs-sc-web-platform/node_modules/lint-staged/lib/index.js:28:48)
    at Object.search (/Users/wenda/apps/acs-sc-web-platform/node_modules/lilconfig/dist/index.js:126:37)
    at async lintStaged (/Users/wenda/apps/acs-sc-web-platform/node_modules/lint-staged/lib/index.js:101:9)

@iiroj
Copy link
Member

iiroj commented Oct 24, 2021

@w3nda
Copy link

w3nda commented Oct 24, 2021

I have lilconfig installed at 2.0.3, I just reinstalled it and getting the same error.

@iiroj
Copy link
Member

iiroj commented Oct 24, 2021

Are you by chance using yaml configuration? That was the one thing not supported directly by lilconfig.

@koshic
Copy link

koshic commented Oct 24, 2021

Are you by chance using yaml configuration? That was the one thing not supported directly by lilconfig.

But it should be reflected in documentation, right? I use .yaml too.

@w3nda
Copy link

w3nda commented Oct 24, 2021

No, I am not using lilconfig directly, and am using lint-staged through husky.

#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

yarn lint-staged

@iiroj
Copy link
Member

iiroj commented Oct 24, 2021

@VladimirGrenaderov there was a compatibility "fix" in PR #981 that should have handled the yaml configurations, but it seems to be broken. I now managed to replicate the bug so I'll try and come up with a fix. Sorry about that!

@iiroj iiroj linked a pull request Oct 24, 2021 that will close this issue
1 task
@iiroj
Copy link
Member

iiroj commented Oct 24, 2021

@9jaboy @w3nda and @VladimirGrenaderov the fix was pretty simple, but it seems we don't cover this code via tests:
#1033

@kelvindecosta
Copy link

Hey everyone!

Ran into the same issue on Linux.
yarn lint-staged exits with 1.

I think the issue is with the resolveConfig function.
For some reason, it works when I rename .lintstagedrc -> .lintstagedrc.json.

Hope this helps!

@iiroj
Copy link
Member

iiroj commented Oct 24, 2021

Thanks @kelvindecosta, I opened a PR that will fix the issue: #1033

@9jaGuy 9jaGuy changed the title v11.2.4 is broken on Windows v11.2.4 is broken for config .lintstagedrc Oct 24, 2021
@tg970
Copy link

tg970 commented Oct 25, 2021

I can also confirm this is an issue in our projects. OSX 11.6, Node 16.10.0, lint-staged 11.2.4. Running npx lint-staged produces nothing. Is there any way we could expedite PR #1033 ? Hoping to not have to go touch each one of our repos to get up and running again. Thanks!!

@ninezero90hy
Copy link

ninezero90hy commented Oct 26, 2021

I was confused.
This problem needs to be solved quickly!

@aaronadamsCA
Copy link

Works, thanks! 🙌

@PaulRBerg
Copy link

PaulRBerg commented Oct 26, 2021

Hey @aaronadamsCA, you mean it works with v11.2.5, don't you?

Update: yeah I can confirm that it works with v11.2.5

@si-saaref
Copy link

@kelvindecosta I was confused i have some issue i try to use your advice but i can't find where .lintstagedrc..
Where is it? Could you tell me?

@si-saaref
Copy link

While i run with yarn lint-staged everything run normally, but when i tried to use npx lint-staged it show error that yarn is not recognized as internal command

`$ npx lint-staged --debug
Running lint-staged with the following config:
{
'.{js,jsx}': 'yarn lint:fix',
'
.{js,jsx,json,css,md}': 'yarn prettier:fix'
}
[STARTED] Preparing...
[SUCCESS] Preparing...
[STARTED] Running tasks...
[STARTED] Running tasks for *.{js,jsx}
[STARTED] Running tasks for *.{js,jsx,json,css,md}
[STARTED] yarn lint:fix
[STARTED] yarn prettier:fix
[FAILED] yarn lint:fix [FAILED]
[FAILED] yarn lint:fix [FAILED]
[FAILED] yarn prettier:fix [FAILED]
[FAILED] yarn prettier:fix [FAILED]
[SUCCESS] Running tasks...
[STARTED] Applying modifications...
[SKIPPED] Skipped because of errors from tasks.
[STARTED] Reverting to original state because of errors...
[SUCCESS] Reverting to original state because of errors...
[STARTED] Cleaning up...
[SUCCESS] Cleaning up...

✖ yarn lint:fix:
'yarn' is not recognized as an internal or external command,
operable program or batch file.

✖ yarn prettier:fix:
'yarn' is not recognized as an internal or external command,
operable program or batch file.`

@kelvindecosta
Copy link

Hey @si-saaref

.lintstagedrc is the configuration file.
In your case, it would be the file with this content:

{
  ".{js,jsx}": "yarn lint:fix",
  ".{js,jsx,json,css,md}": "yarn prettier:fix"
}

As for your error, yarn must be installed on your system globally like so:

npm i -g yarn

Hope this helps!

@si-saaref
Copy link

@kelvindecosta Yes i have created .lintstagedrc.json with the content as you said and also install yarn globally..
Then i try to commit again and it thrown an error same as before

@aaronadamsCA
Copy link

Hey @si-saaref, the bug described in this issue was fixed as of v11.2.5. If you're using an updated version of lint-staged, then you don't need any of the specific advice offered in this thread, because you won't run into this specific issue anymore.

This isn't a great place to ask for general support. But, I've included some below anyway.


It looks like you're trying to use two different package managers at once:

You should choose one package manager for your project and stick with it. Each has its advantages and disadvantages. At a very high level, Yarn 3 is easier to use, but harder to set up; NPM 8 is built into Node.js 16, but harder to use.

If you want to use NPM, you will run npx lint-staged, and your .lintstagedrc will look something like this:

{
  ".{js,jsx}": "npm run-script lint:fix",
  ".{js,jsx,json,css,md}": "npm run-script prettier:fix"
}

And then going forward, any time you see a command that includes yarn, you will need to learn how to rewrite it for NPM.

Package management is one of the least welcoming aspects of the Node.js ecosystem. Many docs and tutorials will assume you use either NPM or Yarn (and often older, incompatible versions, too). But once you learn how to adjust commands for your package manager of choice, it should be smooth sailing.


If you need further assistance, I'd recommend searching and asking on Stack Overflow: https://stackoverflow.com/tags/node.js

@DeadLoss1801
Copy link

"scripts": {
"test": "mocha"
},

try this

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