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

Exploring the dynamic changes in user authentication state with Angular Fire subscriptions

At the moment, I have been listening to authentication state changes in my ngOnInit method of my AppComponent: export class AppComponent implements OnInit { constructor(public fireAuth: AngularFireAuth) { } ngOnInit(): void { this.fireAuth.auth ...

I am looking to display the results table on the same page after submitting a form to filter content. Can you provide guidance on how to achieve this?

Could someone provide guidance on how to approach the coding aspect of my current issue? I have a search form that includes a select form and a text box. Upon submission, a table is generated with results filtered from the form. Should I utilize a sessio ...

What is the function of the npm remove command?

This is my first time using nodejs/npm. I attempted to uninstall reactjs from my system by typing npm remove reactjs@xxx. However, the output I received seemed strange, prompting me to research the command further. Much to my surprise, it turns out that `r ...

Is there a way for me to update the placeholder text in my script from "CHANGE ME

Can anyone help me troubleshoot this code that's not working on my computer? I have a paragraph with the text CHANGE ME inside an element with the id "warning". I want to update this text when the login button is clicked, but it doesn't seem to ...

Flask Server produces a response with a considerable delay when accessed through AJAX

I am currently running 2 servers on localhost, each with different ports. One of them is a basic flask server in Python and its code is provided below: from flask import Flask,jsonify from flask_cors import CORS app = Flask(__name__) CORS(app) @app.rout ...

Interacting with YouTube Data API without requiring user input

I'm currently developing a music website that enables users to create YouTube playlists. Initially, I experimented with JavaScript: https://developers.google.com/youtube/v3/code_samples/javascript The procedure involves an initial authorization ste ...

Using Angular $resource to store an object with arrays

Consider a scenario where we have a User $resource structured as follows: $scope.user = { name: 'John', hobbies: [1, 2, 3] } If we were to save User.save($scope.user) to the server, it would send the following parameters: name: 'John& ...

Encountering a 404 error while attempting to retrieve metadata for @types/node with NPM and Protractor

Encountering an issue while attempting to install Protractor 5.1.2 using npm results in the following error: npm ERR! code E404 npm ERR! 404 Not Found: @types/node@^6.0.46 The installation command used in the root directory is: npm install <a href="/c ...

How can you create a basic click event for a Google Maps marker?

Can a straightforward action be triggered using jQuery or JavaScript when a user clicks on a Google Maps marker? I am attempting to load content into an external div using AJAX when a user clicks on a marker on the map. The following code snippet could se ...

"Duplicate content issue with ng-transclude causing element to render twice

Why is the transcluded directive displaying Name inside directive = Frank twice? I believed I had a good grasp on transclusion, but this specific scenario has left me puzzled. Check out this fiddle for more details <div ng-app="myApp" ng-controller=" ...

The retrieved item has not been linked to the React state

After successfully fetching data on an object, I am attempting to assign it to the state variable movie. However, when I log it to the console, it shows as undefined. import React, {useState, useEffect} from "react"; import Topbar from '../H ...

The hover effect in CSS brings life to list items when filled with content

I am attempting to create an animation for an <li> element that gives the illusion of a fill effect moving from left to right when hovered over. This is my current progress: ul { list-style-type: none; } .hoverTest { float: left; margin-right: 1 ...

Can you provide instructions on utilizing WYSIWYG for real-time label editing?

I am currently developing an online survey creator. The structure of a Question entity is as follows: [Question] int QuestionId { get; set; } int QuestionNumber { get; set; } String QuestionText { get; set; } QuestionType QuestionType { get; } When prese ...

Having trouble resolving errors in Visual Studio Code after failing to properly close a parent function? Learn how to fix this issue

Here we have the code starting with the construct function followed by the parents function public construct() //child { super.construct; } protected construct() //parent { } The issue arises where I am not receiving an er ...

What is the process for publishing an "unstable" or "development" package using npm?

We manage our workflow with two git branches, master and develop. The master branch is kept stable while the develop branch contains untested work. We want teams to be able to pull down the develop work using npm for testing purposes or if they need it an ...

Using JavaScript and Tampermonkey to convert strings from an HTML element into an array

I am trying to change the names of months into numbers and place them in a table cell on a website. I thought using an array would make it easier to reference the month names by their corresponding array numbers, allowing me to add table tags before and af ...

The development process has encountered an issue: ENOENT - the file or directory does not exist

Encountered Full Error Error: ENOENT: file or directory does not exist, open '/home/Project/project/public/desktop/css/desktop.css' at Object.fs.openSync (fs.js:646:18) at Object.fs.readFileSync (fs.js:551:33) at File.read (/home/Project/project ...

I want to locate every child that appears after the <body> element, and extract the HTML of the element containing a specific class within it

It may sound a bit confusing at first, but essentially I have some dynamically generated HTML that resembles the following: <body> <div class="component" id="465a496s5498"> <div class="a-container"> <div class="random-div"> ...

Can the loading of the window be postponed?

I've created a script that displays a message when the user first visits the website. The message then fades out, followed by another section fading in after a short delay. $(window).load(function() { $(".greeting").delay(1500).fadeOut("500"); ...

Choosing all components except for one and its descendants

I am searching for a method to choose all elements except for one specific element and its descendant, which may contain various levels of children/grandchildren or more. What I'm trying to accomplish is something like... $("*").not(".foo, .foo *").b ...