4

I recently updated the dependencies on my React Native project, and we have husky pre-coomit hooks set up. I tried committing now and I get the following error:

myname@MacSelf014 my-project % git commit --amend file:///<path-to-project>/node_modules/listr2/dist/index.js:206 this.options.fields ??= {}; ^^^ SyntaxError: Unexpected token '??=' at Loader.moduleStrategy (internal/modules/esm/translators.js:149:18) husky - pre-commit hook exited with code 1 (error) 

The pre-commit set up looks like this in my package.json:

"lint-staged": { "*.{js,ts,tsx}": [ "eslint --fix", "prettier --write", ] 

I've tried adding node_modules to .husky/_/.gitignore like so:

* node_modules/* 

And the problem persists. Any idea what the issue might be?

3
  • Why would .gitignore-ing node_modules/ in the .husky directory (where it isn't anyway) help? If you run the linting without Husky does it exclude node_modules/? Commented Oct 16, 2023 at 10:24
  • @jonrsharpe I do have node_modules specified in the .gitignore in the root directory of my project, but that doesn't seem to be helping in this case. Yes, the linter ignores node_modules without Husky. Commented Oct 16, 2023 at 10:34
  • And have you told ESLint to use that? It's not in the command Husky is running. Give a minimal reproducible example. Commented Oct 16, 2023 at 10:35

3 Answers 3

10

The problem isn't your linters, it's the listr2 package that husky uses to make nice console messages. It's probably your node version.

Check your node version in the terminal you used to make your commit with node -v and make sure yout have at least v16.

Sources :

Sign up to request clarification or add additional context in comments.

1 Comment

Your answer does not resolve @Rameez Hussain 's problem. They want husky to ignore node_modules, not want to solve error of listr2 package
1

As explained in the lint-staged README

Version v13.3.0 was incorrectly released including code of version v14.0.0. This means the breaking changes of v14 are also included in v13.3.0, the last v13 version released

v13.3.0 contains breaking changes of v14 and NodeJs v14 is not supported anymore. The error you see is related to this.

To fix the issue, you can either install a exact version of lint-staged that is prior to the issue

npm i --save-exact [email protected] 

Or upgrade you NodeJs to v14.


Other Source: https://github.com/lint-staged/lint-staged/issues/1315

Comments

-1

i was having this issue while trying to commit directly from Rider or from Github client, but when i ran the commands from the terminal, git add . git commit -m '' it worked, so i would suggest you try that!

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.