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

Breaks when used in ES Modules context due to requirement for file name extension #394

Open
scottdotweb opened this issue Apr 4, 2022 · 0 comments · May be fixed by #396
Open

Breaks when used in ES Modules context due to requirement for file name extension #394

scottdotweb opened this issue Apr 4, 2022 · 0 comments · May be fixed by #396

Comments

@scottdotweb
Copy link

scottdotweb commented Apr 4, 2022

Environment: Node 16.13.1 on Windows.

On a project where I have "type": "module" in my package.json, the hooks fail with this error:

scott@Fresh MINGW64 ~/Code/Repos/project (main)$ git checkout hooks-test
Switched to branch 'hooks-test'
M       package.json
M       pnpm-lock.yaml
node:internal/errors:464
    ErrorCaptureStackTrace(err);
    ^

TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension "" for C:\Users\scott\Code\Repos\project\.git\hooks\post-checkout
    at new NodeError (node:internal/errors:371:5)
    at Object.file: (node:internal/modules/esm/get_format:72:15)
    at defaultGetFormat (node:internal/modules/esm/get_format:85:    :38)
    at defaultLoad (node:internal/modules/esm/load:13:42)
    at ESMLoader.load (node:internal/modules/esm/loader:303:26)      [39m
    at ESMLoader.moduleProvider (node:internal/modules/esm/loader    r:230:58)
    at new ModuleJob (node:internal/modules/esm/module_job:63:26)    )    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:2    244:11)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:2    281:24) {
  code: 'ERR_UNKNOWN_FILE_EXTENSION'
}

When type is "module", the file with the shebang requires a file name extension (according to this answer on StackOverflow). That's obviously incompatible with Git's requirement for hooks not to have a file name extension. I'm not sure if there's a solution to that.

brady-ds added a commit to brady-ds/ghooks that referenced this issue Apr 27, 2023
Add a `package.json` to `…/.git/hooks/` to force hooks to run as CommonJS, not
modules.

Fixes ghooks-org#394.
brady-ds added a commit to brady-ds/ghooks that referenced this issue Apr 27, 2023
Add a `package.json` to `…/.git/hooks/` to force hooks to run as CommonJS, not
modules.

Fixes ghooks-org#394.
brady-ds added a commit to brady-ds/ghooks that referenced this issue Apr 27, 2023
Add a `package.json` to `…/.git/hooks/` to force hooks to run as CommonJS, not
modules.

Fixes ghooks-org#394.
@brady-ds brady-ds linked a pull request Apr 27, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

1 participant