Husky and lint-staged failing to run on Windows due to 'command not found' error

I'm facing issues with getting husky and lint-staged to function properly on my Windows 10 system.

Here's how my setup looks like:

.huskyrc.json

{
  "hooks": {
    "pre-commit": "lint-staged"
  }
}

.lintstagedrc (content seems irrelevant as the problem arises before this file is even read)

{
  "**/*.+(js|md)": [
    "prettier --write",
    "eslint --fix src/",
    "git add"
  ]
}

package.json

  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --watchAll=false",
    "eject": "react-scripts eject",
    "lint": "eslint .",
    "lint-fix": "eslint . --fix"
  },
  ...
  "devDependencies": {
    ...
    "husky": "^4.3.0",
    "lint-staged": "^10.5.4",
    ...
  }

My npm version is 6.14.11 and node version is 14.15.1.

When I run git add . and git commit -m "test" in the terminal, here's the error message I encounter:

husky > pre-commit (node v14.15.1)
C:\Program Files\nodejs/node_modules/node/bin/node: line 1: This: command not found
husky > pre-commit hook failed (add --no-verify to bypass)

This issue seems to be occurring only on my Windows machine and not on Ubuntu. Any insights on what could be causing this?

Answer №1

For those who have lint-staged installed locally, remember to include the path to lint-staged.

.huskyrc.json

{
  "hooks": {
    "pre-commit": "./node_modules/.bin/lint-staged"
  }
}

An alternative method is to create a script in your package.json that executes lint-staged.

package.json

{
  "scripts": {
    "lint-staged": "lint-staged"
  }
}

Afterward, update your pre-commit hook.

.huskyrc.json

{
  "hooks": {
    "pre-commit": "npm lint-staged"
  }
}

If you prefer, you can also install lint-staged globally and avoid any modifications. Simply run: npm install -g lint-staged

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What could be causing the res.sendfile() method to fail when invoked through a jQuery ajax call?

Problem: The first ajax call in the main.js is functioning correctly, but there seems to be an issue with the second one. Although it appears to be working initially, I suspect that there may be a bug present. Upon clicking the button, I am able to access ...

Is it just me or does my node server come preconfigured with CORS enabled? What am I overlooking here?

I have a simple node and express server set up here. Surprisingly, even without any middleware, I am able to successfully log the response from an axios request made to google.com. Doesn't this usually trigger a cors error, requiring some form of midd ...

modify the color of text in a row within a jquery ajax table

Is it possible to change the font color of values in a row based on a condition inside a function? Specifically, if the TotalStudent count exceeds the room capacity, can we add student information to the table with red font color? Below is my attempt using ...

Assistance needed for disabled JavaScript

I'm currently working on a small application where I need to display some text wrapped in 3 divs. The goal is to only show one div at a time and provide users with prev and next buttons to switch between them. However, when JavaScript is disabled, I w ...

Dismiss MUI Snackbar notification and execute action upon pressing a key

A custom notification system has been developed, utilizing the material ui Snackbar with both an action button and a close button. The objective is to implement a listener event for the "enter" key in order to trigger the specific notification's actio ...

A guide to update values in mongodb using node.js

I'm working on tracking the number of visitors to a website. To do this, I've set up a collection in my database using Mongoose with a default count value of 0. const mongoose = require('mongoose'); const Schema = mongoose. ...

Storing table rows in an array using Javascript

I've encountered a situation where I have a PHP script generating a string of table rows that is then returned via an AJAX request. This generated string consists of all the content enclosed within the tbody tags (<tr>1</tr><tr>2< ...

Defer the rendering of Vue.js pages until the data request is completed

I am currently working on a page that retrieves data from the server using axios. My goal is to wait for the axios request to complete before rendering the page content. The reason behind this approach is that I already have a prerendered version of the ...

What is the process of uploading files using Ajax?

Can anyone help me with submitting a form using ajax that contains images? I have this code snippet which logs an object called "FormData" in the console, but I'm not sure how to properly use it or retrieve it. Is this the correct approach? $("#form_ ...

The placement of the breadcrumb trail is not in the right position

My website includes a menu and breadcrumbs. The menu consists of two submenus: Design Services, Design Portfolio, Design Fees, About Us, Contact Us, Design Resources, Design Vacancies, and Terms. Clicking on Design Services reveals Graphic Design, Logo Des ...

Creating multiple versions of a website based on the user's location can be achieved by implementing geotargeting techniques

It may be a bit challenging to convey this idea clearly. I am interested in creating distinct home pages based on the source from which visitors arrive. For instance, if they come from FaceBook, I envision a tailored home page for FaceBook users. If they ...

Issue with "Access-Control-Allow-Origin" header missing in express and react application

I've decided to work on a Node/Express project to improve my JavaScript skills, but I'm facing an issue with 'Access-Control-Allow-Origin'. For some reason, I can't do a get request from the front end and despite looking at other p ...

Unlock the Power of Angular: Leveraging ViewEncapsulation.Native to Access HTML Elements

I am encountering an issue where I am receiving an error when trying to access an HTML element by ID. The problem arises when I attempt to access the classList upon a user clicking a button to apply a different style class to the element. The class list an ...

Plugin for managing responses other than 200, 301, or 302 in forms

Currently, I am using the jQuery Form Plugin in my project. Everything works smoothly when the server sends a 200 response as it triggers the success listener seamlessly. However, according to the standard protocol, the browser automatically handles 301 ...

Ways to increase the date by one month in this scenario

I am facing an issue with manipulating two date variables. One of the dates is set to last Friday by default, and I am attempting to add a month to this date using the code snippet below. However, it does not produce the desired result. var StartDate = ne ...

Is it feasible to retrieve and view local storage data within an Electron application?

I created an electron application that enables users to drag and drop elements like divs on the screen, saving their positions in localstorage as a class. The purpose is to ensure that any modifications made by the user persist even after reloading or re ...

Unable to locate the internal/fs module, current solutions are proving ineffective

Every time I try to run my project, I encounter the same issue despite downgrading my node version to 8.4.0 (npm version 5.3.0). I have tried various solutions such as removing the node_modules, running npm cache clean --force, and then npm install, but no ...

Is it advisable to utilize media queries and transform: translateY(-%) to position content above the mobile keyboard?

I've been struggling for nearly a whole day and could really use some assistance. I'm having trouble understanding how chat web apps manage to work around this particular issue. There have been numerous forum posts discussing the problem: I am tr ...

Guide to adding items to an array in json-server using a JavaScript-created database

I built a JSON-server app that dynamically generates the database using JavaScript when it starts running. The data I create is organized within a 'users' object, as illustrated below: { "users": [ { "id": "user_id_0", ...

Detecting changes to DOM elements without using jQueryResponding to DOM element

Suppose I have the following HTML structure: <div id='content'></div> I want to receive an alert when there are height mutations on this element. I thought about using the MutationObserver class for this, but I encountered a specifi ...