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

SyntaxError: Unexpected token } in JSON at position 199 at JSON.parse() #1274

Open
tristinnguyentu opened this issue Mar 9, 2023 · 3 comments · Fixed by #1281
Open

SyntaxError: Unexpected token } in JSON at position 199 at JSON.parse() #1274

tristinnguyentu opened this issue Mar 9, 2023 · 3 comments · Fixed by #1281

Comments

@tristinnguyentu
Copy link

Description

I'm using lint-staged 13.1.2 with husky version 8.0.0 and eslint 8.17.0. When trying to commit to my branch, I keep getting an error from the lint-staged node modules:
image

It seems to be referencing the loadConfig.js file's jsonParse() method. I see that there is a searchPlaces array in that file which I'm guessing could be related to the issue, but I don't see any errors with my package.json in terms of brackets, and I don't have another lint-staged config file. The debug logs seem to support the idea that the problem is with my package.json, but I don't even have a

loadConfig.js
image

package.json

{

    "name": "axen-ui",

    "version": "0.0.1",

    "author": "Ionic Framework",

    "homepage": https://ionicframework.com/,

    "scripts": {

        "ng": "ng",

        "start": "sudo ng serve --proxy-config proxy.conf.js",

        "build": "ng build",

        "test": "ng test",

        "lint": "ng lint",

        "style": "npx prettier --write src/",

        "e2e": "ng e2e",

        "prepare": "husky install"

    },

    "private": true,

    "dependencies": {

        "@angular/animations": "^13.3.12",

        "@angular/cdk": "13.0.0",

        "@angular/common": "~13.3.12",

        "@angular/compiler": "~13.3.12",

        "@angular/core": "~13.3.12",

        "@angular/forms": "~13.3.12",

        "@angular/platform-browser": "~13.3.12",

        "@angular/platform-browser-dynamic": "~13.3.12",

        "@angular/router": "~13.3.12",

        "@angular/service-worker": "~13.3.12",

        "@fusioncharts/fusiontime": "^2.6.0",

        "@ionic-native/core": "^5.0.0",

        "@ionic-native/splash-screen": "^5.0.0",

        "@ionic-native/status-bar": "^5.0.0",

        "@ionic/angular": "^6.1.10",

        "@ionic/storage": "^2.2.0",

        "@kolkov/angular-editor": "^3.0.0-beta.0",

        "@syncfusion/ej2-angular-calendars": "19.2.62",

        "@types/chrome": "0.0.89",

        "@types/file-saver": "^2.0.1",

        "@types/hammerjs": "^2.0.36",

        "angular-fusioncharts": "^4.0.0",

        "assert": "^2.0.0",

        "cordova-browser": "6.0.0",

        "core-js": "^2.5.4",

        "date-fns": "^2.28.0",

        "dom-to-image": "^2.6.0",

        "exceljs": "^1.12.0",

        "file-saver": "^2.0.2",

        "fusioncharts": "^3.15.0-sr.1",

        "hammerjs": "^2.0.8",

        "html2canvas": "^1.0.0-rc.5",

        "idb-keyval": "^3.2.0",

        "ionic-input-mask": "^1.0.1",

        "ionic-selectable": "^4.9.0",

        "keyword-highlighter": "^1.0.6",

        "ng-starrating": "^1.0.20",

        "ng2-datepicker": "^3.1.1",

        "ngx-cookie-service": "^11.0.2",

        "ngx-device-detector": "^1.3.19",

        "ngx-mask": "^15.0.2",

        "ngx-pagination": "^5.0.0",

        "ngx-perfect-scrollbar": "^8.0.0",

        "rxjs": "^6.5.5",

        "rxjs-compat": "^6.5.5",

        "tslib": "^1.10.0",

        "util": "^0.12.4",

        "yup": "^0.32.11",

        "zone.js": "~0.11.4"

    },

    "devDependencies": {

        "@angular-builders/custom-webpack": "^8.2.0",

        "@angular-devkit/architect": "~0.1303.10",

        "@angular-devkit/build-angular": "~13.3.10",

        "@angular-devkit/core": "~13.3.10",

        "@angular-devkit/schematics": "~13.3.10",

        "@angular-eslint/builder": "13.5.0",

        "@angular-eslint/eslint-plugin": "13.5.0",

        "@angular-eslint/eslint-plugin-template": "13.5.0",

        "@angular-eslint/schematics": "^13.5.0",

        "@angular-eslint/template-parser": "13.5.0",

        "@angular/cli": "~13.3.10",

        "@angular/compiler-cli": "~13.3.12",

        "@angular/language-service": "~13.3.12",

        "@ionic/angular-toolkit": "^2.1.2",

        "@types/chrome": "0.0.89",

        "@types/jasmine": "~3.3.8",

        "@types/jasminewd2": "~2.0.3",

        "@types/node": "^12.20.54",

        "@types/underscore": "^1.9.3",

        "@typescript-eslint/eslint-plugin": "5.27.1",

        "@typescript-eslint/parser": "5.27.1",

        "cordova-plugin-device": "^2.0.2",

        "cordova-plugin-ionic-keyboard": "^2.2.0",

        "cordova-plugin-ionic-webview": "^4.1.3",

        "cordova-plugin-splashscreen": "^5.0.2",

        "cordova-plugin-statusbar": "^2.4.2",

        "cordova-plugin-whitelist": "^1.3.3",

        "eslint": "^8.17.0",

        "husky": "^8.0.0",

        "jasmine-core": "~3.4.0",

        "jasmine-spec-reporter": "~4.2.1",

        "karma": "^6.3.6",

        "karma-chrome-launcher": "~2.2.0",

        "karma-coverage-istanbul-reporter": "~2.0.1",

        "karma-jasmine": "~2.0.1",

        "karma-jasmine-html-reporter": "^1.4.0",

        "lint-staged": "^13.1.2",

        "prettier": "^2.8.4",

        "protractor": "^7.0.0",

        "puppeteer": "^11.0.0",

        "stylelint": "^15.2.0",

        "stylelint-config-standard": "^30.0.1",

        "stylelint-config-standard-scss": "^7.0.1",

        "ts-node": "~7.0.0",

        "typescript": "~4.6.4",

        "webpack": "^5.75.0",

        "webpack-dev-server": "^4.11.1",

        "webpack-extension-reloader": "^1.1.1"

    },

    "description": "An Ionic project",

    "cordova": {

        "plugins": {

            "cordova-plugin-whitelist": {},

            "cordova-plugin-statusbar": {},

            "cordova-plugin-device": {},

            "cordova-plugin-splashscreen": {},

            "cordova-plugin-ionic-webview": {},

            "cordova-plugin-ionic-keyboard": {}

        },

        "platforms": [

            "browser"

        ]

    },

    "browser": {

        "fs": false,

        "path": false,

        "os": false

    },

    "resolve": {

        "alias": {

            "process": "process/browser"

        }

    },

    "lint-staged": {

        "src/**/*.{js,ts,html,css,scss,json}": "prettier --write --ignore-unknown",

        "src/**/*.{js,ts}": "eslint --fix",

        "src/**/*.{css,scss}": "stylelint --fix"


    }

}

Steps to reproduce

Make a commit with husky pre-commit hook.

Debug Logs

expand to view

image

Environment

  • OS: macOS Ventura
  • Node.js: v16.19.0
  • lint-staged: 13.1.2
@mjborys
Copy link

mjborys commented Mar 9, 2023

I am seeing a similar error when trying to commit from VSCode, which worked until I updated VSCode recently (current VSCode version info below). As of the latest VSCode version I can no longer commit from the VSCode interface, I get the following error. I can commit from the command line just fine, however.

> git -c user.useConfigOnly=true commit --quiet
yarn run v1.22.17
$ redacted/node_modules/.bin/lint-staged
file:///redacted/node_modules/lint-staged/lib/index.js:113
    if (runAllError?.ctx?.errors) {
                    ^

SyntaxError: Unexpected token '.'
    at Loader.moduleStrategy (internal/modules/esm/translators.js:140:18)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
husky - pre-commit hook exited with code 1 (error)

If I downgrade lint-staged to 12.5.0 it works fine.

image

@tristinnguyentu
Copy link
Author

Downgrading to 12.5.0 didn't resolve my issue, plus it doesn't let me commit whether it's through GitHub desktop or the CLI. Running npx lint-staged with the --debug flag seems to show that the issue is with parsing my package.json, but I don't see what's wrong with it.

@iiroj
Copy link
Member

iiroj commented Apr 7, 2023

Would version 13.2.1 work any better?

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.

3 participants