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 {' when running eslint hook. #1682

Closed
HaGuesto opened this issue Nov 5, 2020 · 4 comments
Closed

'SyntaxError: Unexpected token {' when running eslint hook. #1682

HaGuesto opened this issue Nov 5, 2020 · 4 comments
Labels

Comments

@HaGuesto
Copy link

HaGuesto commented Nov 5, 2020

I'm trying to migrate in our new mono-repo the frontend linting on staged files from husky to pre-commit as recommended here.

When I try to run

pre-commit run eslint

I get the following error

eslint...................................................................Failed
- hook id: eslint
- duration: 0.06s
- exit code: 1

/home/hans/.cache/pre-commit/repo0q_v76eh/node_env-system/lib/node_modules/eslint/bin/eslint.js:93
        } catch {
                ^

SyntaxError: Unexpected token {
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:617:28)
    at Object.Module._extensions..js (module.js:664:10)
    at Module.load (module.js:566:32)
    at tryModuleLoad (module.js:506:12)
    at Function.Module._load (module.js:498:3)
    at Function.Module.runMain (module.js:694:10)
    at startup (bootstrap_node.js:204:16)
    at bootstrap_node.js:625:3

This is the eslint hook in the pre-commit-config.yaml

- repo: https://github.com/pre-commit/mirrors-eslint
  rev: v7.12.1
  hooks:
  - id: eslint
    verbose: true
    args: ['--fix']
    additional_dependencies: ['eslint@7.12.1', 'eslint-plugin-jsx-a11y']
    files: \.[jt]sx?$ 
    types: [file]

My pre-commit version is 2.8.2

@asottile
Copy link
Member

asottile commented Nov 5, 2020

what does node --version and npm --version give you?

@HaGuesto
Copy link
Author

HaGuesto commented Nov 5, 2020

node v12.15.0
npm 6.13.4

Do I have to have node installed locally for eslint to work? Does it not use the nodeenv?

@asottile
Copy link
Member

asottile commented Nov 5, 2020

ah yeah that looks probably too old for that syntax

this changed recently, if pre-commit sees a global node + npm it will default to nodeenv -n system -- you can restore the old behaviour by using language_version: default (this defaults to latest node+npm) -- either on a per-hook bases or globally with default_language_version

@HaGuesto
Copy link
Author

HaGuesto commented Nov 5, 2020

Thanks for the quick help!
So, I'm trying to set the version in pre-commit-config.yaml since I have to prepare this for people who do not regularly work with node/npm and I do want to force them to update.

The first option - adding language_version: default to the hook - still produced the same error.
The second option - specifying the version globally - worked

default_language_version:
  node: 15.1.0

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

No branches or pull requests

2 participants