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

[bug] commitlint.config.js:1 SyntaxError: Invalid or unexpected token #614

Closed
2 tasks
indraraj26 opened this issue Apr 5, 2019 · 9 comments
Closed
2 tasks

Comments

@indraraj26
Copy link

By Default in VS code i have UTF-8 still it gives me error

commitlint.config.js

module.exports = {extends: ['@commitlint/config-conventional']}

Expected Behavior

it shouldn't be throw any error

Current Behavior

git commit -m "feat: initial commit"
husky > pre-commit (node v8.14.0)


All files pass linting.


All files pass linting.
husky > commit-msg (node v8.14.0)
D:\ng\commitlint.config.js:1
(function (exports, require, module, __filename, __dirname) { ��m
                                                              ^

SyntaxError: Invalid or unexpected token
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:617:28)
    at requireFromString (D:\ng-sma\node_modules\require-from-string\index.js:28:4)
    at parseJsFile (D:\ng-sma\node_modules\cosmiconfig\dist\loadJs.js:15:15)
    at <anonymous>
husky > commit-msg hook failed (add --no-verify to bypass)

I am not sure which one will i have to select.

Affected packages

  • [ X ] cli
  • core
  • prompt
  • [ X ] config-angular

Possible Solution

Steps to Reproduce (for bugs)

  1. create a sample project of latest angular 7.2.2
  2. install husky and commitlint
  3. add this in package.json
"husky": {
    "hooks": {
      "pre-commit": "ng lint",
      "commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
    }
  }
commitlint.config.js ```js ```

Context

Your Environment

Package.json

"husky": "^1.3.1", 
"@commitlint/cli": "^7.5.2",
"@commitlint/config-conventional": "^7.5.0",

i get this in console VS code powershell

PS D:\ng> commitlint --version
commitlint : The term 'commitlint' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if 
a path was included, verify that the path is correct and try again.
At line:1 char:1
+ commitlint --version
+ ~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (commitlint:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
Executable Version
git --version 2.19.1.windows.1
node --version v8.14.0
@escapedcat
Copy link
Member

escapedcat commented Apr 5, 2019

I don't have a windows machine to test this, but looking at older isses others seem to have solved this:

@indraraj26
Copy link
Author

This one is telling me to have Encoding utf-8 #270 which is already, i have.

#231 has not answered solution properly. what do you mean by windows line ending ?

@YupongUU
Copy link

YupongUU commented Apr 8, 2019

I got the same error. Any one else solve this problem?

@xCykrix
Copy link

xCykrix commented Apr 20, 2019

@indraraj26 @YupongUU can you upload the exact commitlint.config.js, it is likely an encoding issue and only the exact file could help us replicate it.

@indraraj26
Copy link
Author

Hey @xCykrix ,

Here is mine commitlint.config.js
https://gofile.io/?c=cPkb0A

Thank you.

@xCykrix
Copy link

xCykrix commented Apr 23, 2019

@indraraj26 for yours, make sure it is encoded with UTF-8. The file you sent me appears to be encoded with UTF-16 LE, which is known to cause issues.

You can modify this in VSCode in the bottom right. Other editors may vary.
VSCode-BottomRight

Properly encoded reference, if you need it to copy text from.
https://cdn.amethyst.studio/u/samuel/bins/d444

@indraraj26
Copy link
Author

Hey @xCykrix , I can see clearly in vs code, I have encoding utf-8 , i dont know why it is taking UTF-16LE as per you.

If i copy text from above link and paste in commitlink.config.js will that work?

Thank you

@marionebl
Copy link
Contributor

commitlint uses cosmiconfig to load configuration and does nothing regarding parsing/reading those files. Please consider opening this issue with cosmiconfig if the problem persists.

@cy0707
Copy link

cy0707 commented Aug 6, 2019

in window, you can try delete this file, and create new file,do not use command line

echo "module.exports = {extends: ['@commitlint/config-conventional']};" > commitlint.config.js

in editor (vscode), wirte code

@conventional-changelog conventional-changelog locked as resolved and limited conversation to collaborators Aug 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

6 participants