simple-git-hooks icon indicating copy to clipboard operation
simple-git-hooks copied to clipboard

Add windows compatibility to `npx simple-git-hooks` when configured by `.js` file

Open toplenboren opened this issue 3 years ago • 2 comments

When setting the configuration from js file (simple-git-hooks.js or .simple-git-hooks.js) the npx simple-git-hooks command executed on Windows 10 returns an error:

Line:       1
Char:      1
Error:      'module' is not defined
Source:  Microsoft JScript runtime error

The problem happens because for some reason Windows might use internal JS interpreter instead of node. This internal interpreter does not know what module is, thus throwing an error.

--

Possible workaround for now is to use configuration from package.json or simple-git-hooks.json files.

Also changing the default interpreter might help

toplenboren avatar Mar 23 '21 12:03 toplenboren

Hey, actually it did work for me today. I'm on windows 10 with configuration in .simple-git-hooks.js. Here is PR if you want to check settings/deps/etc.: https://github.com/nolimits4web/swiper/pull/4417

P.S Using bash if relevant

vltansky avatar Apr 08 '21 12:04 vltansky

The problem is that Windows doesn't support shebangs. So, running foo.js will use the default program associated with .js files, which is usually wscript. The solution is to use exec from Node.js and use node foo.js across the codebase.

XhmikosR avatar May 01 '22 05:05 XhmikosR