fix: SyntaxError: Invalid or unexpected token. commit-msg run error.
Expected Behavior
PS E:\all_project\original-detection> git commit -m 'test commit-msg' → No staged files match any configured task. E:\all_project\original-detection\node_modules.pnpm@[email protected]\node_modules@commitlint\read\lib\read.js:1
SyntaxError: Invalid or unexpected token
at internalCompileFunction (node:internal/vm:73:18)
at wrapSafe (node:internal/modules/cjs/loader:1176:20)
at Module._compile (node:internal/modules/cjs/loader:1218:27)
at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
at Module.load (node:internal/modules/cjs/loader:1117:32)
at Module._load (node:internal/modules/cjs/loader:958:12)
at Module.require (node:internal/modules/cjs/loader:1141:19)
at require (node:internal/modules/cjs/helpers:110:18)
at Object.
Node.js v18.16.0 husky - commit-msg hook exited with code 1 (error)
Current Behavior
No response
Affected packages
- [ ] cli
- [ ] core
- [ ] prompt
- [ ] config-angular
Possible Solution
No response
Steps to Reproduce
1. pnpm add @commitlint/config-conventional @commitlint/cli husky
2. echo "module.exports = {extends: ['@commitlint/config-conventional']}" > commitlint.config.js
3. npx husky install
4. npx husky add .husky/commit-msg 'npx --no -- commitlint --edit ${1}'
5. git add .
6. git commit -m 'test pre-commit'
Context
verify commit message
commitlint --version
"@commitlint/cli": "^17.6.1"
git --version
git version 2.37.3.windows.1
node --version
v18.16.0
Tried with node v18.15.0 on OSX
echo "test pre-commit" | npx commitlint
â§— input: test pre-commit
✖ subject may not be empty [subject-empty]
✖ type may not be empty [type-empty]
✖ found 2 problems, 0 warnings
ⓘ Get help: https://github.com/conventional-changelog/commitlint/#what-is-commitlint
Did you search the existing issues already? Might be one of these:
- #614
- #231
I got the same bug. Any one else solve this bug?
I just figured out what was causing this error in my context.
Problem
After hours of reading documentation for errors in husky, lint-staged and commitlint, none of them worked.
I found that what was preventing the commitlint cli from working was the my tsconfig file.
Configuration file
// tsconfig.json
{
"extends": [
"@tsconfig/node12"
],
"compilerOptions": {
// configs ...
}
}
Prompt
dwesley@DESKTOP-R4V89G6:~/www/new-beecrowd$ git commit -m "TEST"
→ No staged files match any configured task.
--- COMMIT-MSG HOOK ---
/home/dwesley/www/new-beecrowd/node_modules/@commitlint/cli/lib/cli.js:123
throw err;
^
TypeError: value.replace is not a function
at normalizeSlashes (/home/dwesley/www/new-beecrowd/node_modules/ts-node/dist/util.js:62:18)
at Object.getExtendsConfigPath (/home/dwesley/www/new-beecrowd/node_modules/ts-node/dist/ts-internals.js:24:54)
at readConfig (/home/dwesley/www/new-beecrowd/node_modules/ts-node/dist/configuration.js:127:64)
at findAndReadConfig (/home/dwesley/www/new-beecrowd/node_modules/ts-node/dist/configuration.js:50:84)
at create (/home/dwesley/www/new-beecrowd/node_modules/ts-node/dist/index.js:146:69)
at register (/home/dwesley/www/new-beecrowd/node_modules/ts-node/dist/index.js:127:19)
at TypeScriptLoader (/home/dwesley/www/new-beecrowd/node_modules/cosmiconfig-typescript-loader/dist/cjs/index.js:52:54)
at loadConfig (/home/dwesley/www/new-beecrowd/node_modules/@commitlint/load/lib/utils/load-config.js:12:75)
at load (/home/dwesley/www/new-beecrowd/node_modules/@commitlint/load/lib/load.js:19:55)
at main (/home/dwesley/www/new-beecrowd/node_modules/@commitlint/cli/lib/cli.js:194:45)
Node.js v18.15.0
husky - commit-msg hook exited with code 1 (error)
Solution
By removing this specific setting, everything went back to normal.
Configuration file
// tsconfig.json
{
"extends": [
// "@tsconfig/node12"
],
"compilerOptions": {
// configs ...
}
}
Prompt
dwesley@DESKTOP-R4V89G6:~/www/new-beecrowd$ git commit -m "TEST"
→ No staged files match any configured task.
--- COMMIT-MSG HOOK ---
â§— input: TEST
✖ subject may not be empty [subject-empty]
✖ type may not be empty [type-empty]
✖ found 2 problems, 0 warnings
ⓘ Get help: https://github.com/conventional-changelog/commitlint/#what-is-commitlint
husky - commit-msg hook exited with code 1 (error)
Suggestion
I believe that, somehow, my project settings interfered with the execution of the lib. Ideally, this shouldn't happen. I believe this error is a point that the lib should resolve permanently.
@DavidWesley your issue sounds like #3256
@rangersss issue could be something else. Not sure.
@DavidWesley your issue sounds like #3256 @rangersss issue could be something else. Not sure.
The problem is the npm package
Sure, but is it the same as #3256 ?
Sure, but is it the same as #3256 ?
Yes, because there may be some problem with the package when downloading with pnpm before, and then there will be no problem after re-downloading the package with yarn!
Sorry, I do not understand.
#3256 is about a conflicting tsconfig.
If your issue is about pnpm vs. yarn this is a different issue.
It looks like a problem with typescript v5 and https://github.com/TypeStrong/ts-node/pull/1958, ts-node is currently not supporting extends as array
~Please see if the latest release fixes this: https://github.com/conventional-changelog/commitlint/releases/tag/v17.7.0~
See #3641 This will then hopefully be fixed with a new mayor version. yolo