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

fix: SyntaxError: Invalid or unexpected token. commit-msg run error. #3588

Open
4 tasks
rangersss opened this issue Apr 23, 2023 · 10 comments
Open
4 tasks

fix: SyntaxError: Invalid or unexpected token. commit-msg run error. #3588

rangersss opened this issue Apr 23, 2023 · 10 comments

Comments

@rangersss
Copy link

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. (E:\all_project\original-detection\node_modules.pnpm@[email protected]\node_modules@commitlint\cli\lib\cli.js:16:32)
at Module._compile (node:internal/modules/cjs/loader:1254:14)

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

@rangersss rangersss added the bug label Apr 23, 2023
@escapedcat
Copy link
Member

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:

@escapedcat escapedcat removed the bug label Apr 24, 2023
@DavidWesley
Copy link

I got the same bug. Any one else solve this bug?

@DavidWesley
Copy link

DavidWesley commented Apr 25, 2023

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.

@escapedcat
Copy link
Member

@DavidWesley your issue sounds like #3256
@rangersss issue could be something else. Not sure.

@rangersss
Copy link
Author

@DavidWesley your issue sounds like #3256 @rangersss issue could be something else. Not sure.

The problem is the npm package

@escapedcat
Copy link
Member

Sure, but is it the same as #3256 ?

@rangersss
Copy link
Author

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!

@escapedcat
Copy link
Member

Sorry, I do not understand.
#3256 is about a conflicting tsconfig.
If your issue is about pnpm vs. yarn this is a different issue.

@prisis
Copy link

prisis commented May 15, 2023

It looks like a problem with typescript v5 and TypeStrong/ts-node#1958, ts-node is currently not supporting extends as array

@escapedcat
Copy link
Member

escapedcat commented Aug 9, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants