The keyword const is reserved как исправить

I am getting this error from ESLint: error Parsing error: The keyword 'const' is reserved from this code: const express = require('express'); const app = express(); const _ = require('underscor...

I am getting this error from ESLint:

error  Parsing error: The keyword 'const' is reserved

from this code:

const express = require('express');
const app = express();
const _ = require('underscore');

I’ve tried removing node_modules and reinstalling all npm packages (as suggested here), but to no avail.

MultiplyByZer0's user avatar

asked Mar 9, 2017 at 22:19

opike's user avatar

ESLint defaults to ES5 syntax-checking.
You’ll want to override to the latest well-supported version of JavaScript.

Try adding a .eslintrc.json file to your project. Inside it:

{
    "parserOptions": {
        "ecmaVersion": "latest"
    },

    "env": {
        "es6": true
    }
}

Hopefully this helps.

EDIT: I also found this example .eslintrc.json which might help.

answered Mar 9, 2017 at 22:26

iamjpg's user avatar

iamjpgiamjpg

6,6081 gold badge16 silver badges17 bronze badges

3

you also can add this inline instead of config, just add it to the same file before you add your own disable stuff

/* eslint-env es6 */
/* eslint-disable no-console */

my case was disable a file and eslint-disable were not working for me alone

/* eslint-env es6 */
/* eslint-disable */

answered Nov 21, 2018 at 21:32

yousef's user avatar

yousefyousef

1,18011 silver badges13 bronze badges

4

I used .eslintrc.js and I have added following code.

module.exports = {
    "parserOptions": {
        "ecmaVersion": 6
    }
};

answered Jun 17, 2018 at 9:34

KHACHORNCHIT's user avatar

KHACHORNCHITKHACHORNCHIT

2,15622 silver badges18 bronze badges

0

Update — ESLint v7.30.0

With ESLint v7.30.0, you can use latest instead of 2017, and it will enable the latest supported ECMAScript version.

«ecmaVersion»: «latest» always enables the latest supported ECMAScript
version in ESLint’s default parser.

.eslintrc.json

"parserOptions": {
  "ecmaVersion": "latest"
}

answered Nov 26, 2021 at 15:24

NeNaD's user avatar

NeNaDNeNaD

16.3k7 gold badges36 silver badges81 bronze badges

If using Visual Code one option is to add this to the settings.json file:

"eslint.options": {
    "useEslintrc": false,
    "parserOptions": {
        "ecmaVersion": 2017
    },
    "env": {
        "es6": true
    }
}

answered Nov 25, 2019 at 17:32

Bjørnar Hvidsten's user avatar

I had this same problem with this part of my code:

const newComment = {
    dishId: dishId,
    rating: rating,
    author: author,
    comment: comment
};
newComment.date = new Date().toISOString();

Same error, const is a reserved word.

The thing is, I made the .eslintrc.js from the link you gave in the update and still got the same error. Also, I get an parsing error in the .eslintrc.js: Unexpected token ':'.

Right in this part:

"env": {
  "browser": true,
  "node": true,
  "es6": true
},

...

Dan Atkinson's user avatar

Dan Atkinson

11.3k14 gold badges82 silver badges112 bronze badges

answered Oct 14, 2018 at 0:10

Marcos Sevilla's user avatar

I used the config in .eslintrc.json as mentioned in the accepted answer:

{
  parserOptions: {
    "ecmaVersion": "latest"
  },
  env: {
    "es6": true
  }
}

It was also necessary to add to settings.json:

"eslint.options": { "configFile": "eslintrc.json" }

answered Jan 20 at 10:02

Mike's user avatar

MikeMike

534 bronze badges

I had this issue when updating. I had an eslintrc.json in the project already as well. I just closed my project in Visual Studio Code and reopened it and the error went away. It seems VS Code caches.

answered Sep 25, 2021 at 1:00

Curtis M's user avatar

Curtis MCurtis M

7651 gold badge7 silver badges14 bronze badges

In my case, it was unable to find the .eslintrc file so I copied from node_modules/.bin to root.

answered Jan 8, 2020 at 17:28

I am getting this error from ESLint:

error  Parsing error: The keyword 'const' is reserved

from this code:

const express = require('express');
const app = express();
const _ = require('underscore');

I’ve tried removing node_modules and reinstalling all npm packages (as suggested here), but to no avail.

MultiplyByZer0's user avatar

asked Mar 9, 2017 at 22:19

opike's user avatar

ESLint defaults to ES5 syntax-checking.
You’ll want to override to the latest well-supported version of JavaScript.

Try adding a .eslintrc.json file to your project. Inside it:

{
    "parserOptions": {
        "ecmaVersion": "latest"
    },

    "env": {
        "es6": true
    }
}

Hopefully this helps.

EDIT: I also found this example .eslintrc.json which might help.

answered Mar 9, 2017 at 22:26

iamjpg's user avatar

iamjpgiamjpg

6,6081 gold badge16 silver badges17 bronze badges

3

you also can add this inline instead of config, just add it to the same file before you add your own disable stuff

/* eslint-env es6 */
/* eslint-disable no-console */

my case was disable a file and eslint-disable were not working for me alone

/* eslint-env es6 */
/* eslint-disable */

answered Nov 21, 2018 at 21:32

yousef's user avatar

yousefyousef

1,18011 silver badges13 bronze badges

4

I used .eslintrc.js and I have added following code.

module.exports = {
    "parserOptions": {
        "ecmaVersion": 6
    }
};

answered Jun 17, 2018 at 9:34

KHACHORNCHIT's user avatar

KHACHORNCHITKHACHORNCHIT

2,15622 silver badges18 bronze badges

0

Update — ESLint v7.30.0

With ESLint v7.30.0, you can use latest instead of 2017, and it will enable the latest supported ECMAScript version.

«ecmaVersion»: «latest» always enables the latest supported ECMAScript
version in ESLint’s default parser.

.eslintrc.json

"parserOptions": {
  "ecmaVersion": "latest"
}

answered Nov 26, 2021 at 15:24

NeNaD's user avatar

NeNaDNeNaD

16.3k7 gold badges36 silver badges81 bronze badges

If using Visual Code one option is to add this to the settings.json file:

"eslint.options": {
    "useEslintrc": false,
    "parserOptions": {
        "ecmaVersion": 2017
    },
    "env": {
        "es6": true
    }
}

answered Nov 25, 2019 at 17:32

Bjørnar Hvidsten's user avatar

I had this same problem with this part of my code:

const newComment = {
    dishId: dishId,
    rating: rating,
    author: author,
    comment: comment
};
newComment.date = new Date().toISOString();

Same error, const is a reserved word.

The thing is, I made the .eslintrc.js from the link you gave in the update and still got the same error. Also, I get an parsing error in the .eslintrc.js: Unexpected token ':'.

Right in this part:

"env": {
  "browser": true,
  "node": true,
  "es6": true
},

...

Dan Atkinson's user avatar

Dan Atkinson

11.3k14 gold badges82 silver badges112 bronze badges

answered Oct 14, 2018 at 0:10

Marcos Sevilla's user avatar

I used the config in .eslintrc.json as mentioned in the accepted answer:

{
  parserOptions: {
    "ecmaVersion": "latest"
  },
  env: {
    "es6": true
  }
}

It was also necessary to add to settings.json:

"eslint.options": { "configFile": "eslintrc.json" }

answered Jan 20 at 10:02

Mike's user avatar

MikeMike

534 bronze badges

I had this issue when updating. I had an eslintrc.json in the project already as well. I just closed my project in Visual Studio Code and reopened it and the error went away. It seems VS Code caches.

answered Sep 25, 2021 at 1:00

Curtis M's user avatar

Curtis MCurtis M

7651 gold badge7 silver badges14 bronze badges

In my case, it was unable to find the .eslintrc file so I copied from node_modules/.bin to root.

answered Jan 8, 2020 at 17:28

I am getting this error from ESLint:

error  Parsing error: The keyword 'const' is reserved

from this code:

const express = require('express');
const app = express();
const _ = require('underscore');

I’ve tried removing node_modules and reinstalling all npm packages (as suggested here), but to no avail.

MultiplyByZer0's user avatar

asked Mar 9, 2017 at 22:19

opike's user avatar

ESLint defaults to ES5 syntax-checking.
You’ll want to override to the latest well-supported version of JavaScript.

Try adding a .eslintrc.json file to your project. Inside it:

{
    "parserOptions": {
        "ecmaVersion": "latest"
    },

    "env": {
        "es6": true
    }
}

Hopefully this helps.

EDIT: I also found this example .eslintrc.json which might help.

answered Mar 9, 2017 at 22:26

iamjpg's user avatar

iamjpgiamjpg

6,6081 gold badge16 silver badges17 bronze badges

3

you also can add this inline instead of config, just add it to the same file before you add your own disable stuff

/* eslint-env es6 */
/* eslint-disable no-console */

my case was disable a file and eslint-disable were not working for me alone

/* eslint-env es6 */
/* eslint-disable */

answered Nov 21, 2018 at 21:32

yousef's user avatar

yousefyousef

1,18011 silver badges13 bronze badges

4

I used .eslintrc.js and I have added following code.

module.exports = {
    "parserOptions": {
        "ecmaVersion": 6
    }
};

answered Jun 17, 2018 at 9:34

KHACHORNCHIT's user avatar

KHACHORNCHITKHACHORNCHIT

2,15622 silver badges18 bronze badges

0

Update — ESLint v7.30.0

With ESLint v7.30.0, you can use latest instead of 2017, and it will enable the latest supported ECMAScript version.

«ecmaVersion»: «latest» always enables the latest supported ECMAScript
version in ESLint’s default parser.

.eslintrc.json

"parserOptions": {
  "ecmaVersion": "latest"
}

answered Nov 26, 2021 at 15:24

NeNaD's user avatar

NeNaDNeNaD

16.3k7 gold badges36 silver badges81 bronze badges

If using Visual Code one option is to add this to the settings.json file:

"eslint.options": {
    "useEslintrc": false,
    "parserOptions": {
        "ecmaVersion": 2017
    },
    "env": {
        "es6": true
    }
}

answered Nov 25, 2019 at 17:32

Bjørnar Hvidsten's user avatar

I had this same problem with this part of my code:

const newComment = {
    dishId: dishId,
    rating: rating,
    author: author,
    comment: comment
};
newComment.date = new Date().toISOString();

Same error, const is a reserved word.

The thing is, I made the .eslintrc.js from the link you gave in the update and still got the same error. Also, I get an parsing error in the .eslintrc.js: Unexpected token ':'.

Right in this part:

"env": {
  "browser": true,
  "node": true,
  "es6": true
},

...

Dan Atkinson's user avatar

Dan Atkinson

11.3k14 gold badges82 silver badges112 bronze badges

answered Oct 14, 2018 at 0:10

Marcos Sevilla's user avatar

I used the config in .eslintrc.json as mentioned in the accepted answer:

{
  parserOptions: {
    "ecmaVersion": "latest"
  },
  env: {
    "es6": true
  }
}

It was also necessary to add to settings.json:

"eslint.options": { "configFile": "eslintrc.json" }

answered Jan 20 at 10:02

Mike's user avatar

MikeMike

534 bronze badges

I had this issue when updating. I had an eslintrc.json in the project already as well. I just closed my project in Visual Studio Code and reopened it and the error went away. It seems VS Code caches.

answered Sep 25, 2021 at 1:00

Curtis M's user avatar

Curtis MCurtis M

7651 gold badge7 silver badges14 bronze badges

In my case, it was unable to find the .eslintrc file so I copied from node_modules/.bin to root.

answered Jan 8, 2020 at 17:28

Содержание

  1. Bug: Parsing error: The keyword ‘const’ is reserved #16174
  2. <>’s edit
  3. Environment
  4. What parser are you using?
  5. What did you do?
  6. What did you expect to happen?
  7. What actually happened?
  8. Participation
  9. Additional comments
  10. Replies: 1 suggested answer
  11. Insert Link
  12. Footer
  13. eslint errors on ‘interface’ keyword even when using this parser #620
  14. Comments
  15. Footer
  16. ERROR: Parsing error: The keyword ‘const’ is reserved #14966
  17. Comments
  18. Prerequisites
  19. Description
  20. Steps to Reproduce
  21. Versions
  22. Parsing error: The keyword ‘const’ is reserved #28
  23. Comments
  24. Parsing error: The keyword ‘export’ is reserved #1464
  25. Comments

Bug: Parsing error: The keyword ‘const’ is reserved #16174

<>’s edit

Environment

Node version: 16.5.0
yarn version: 1.22.10
Local ESLint version: latest
Global ESLint version: latest
Operating System: Widnows

What parser are you using?

What did you do?

What did you expect to happen?

it’s supposed to lint a string that looks like this :

What actually happened?

I received this error:

Participation

  • I am willing to submit a pull request for this issue.

Beta Was this translation helpful? Give feedback.

1 You must be logged in to vote

the default ecmaVersion is 5, you’ll need to config it >=6, to use the features like let/const .

the default ecmaVersion is 5, you’ll need to config it >=6, to use the features like let/const .

Beta Was this translation helpful? Give feedback.

Marked as answer

1 You must be logged in to vote

Converted from issue

This discussion was converted from issue #16172 on August 01, 2022 21:44.

Add heading text

Add italic text,

Insert Link

Add a bulleted list,

Add a numbered list,

Add a task list,

Directly mention a user or team

Reference an issue or pull request

Add heading text

Add italic text,

Add a bulleted list,

Add a numbered list,

Add a task list,

© 2023 GitHub, Inc.

You can’t perform that action at this time.

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.

Источник

eslint errors on ‘interface’ keyword even when using this parser #620

I have Babel, ESLint, and Flow all being used in my React Native project. My .eslintrc looks like this:

For some reason, I’m getting an error when I try to declare an interface type in my code:

Not sure why. Could I have setup something wrong?

The text was updated successfully, but these errors were encountered:

Hi @jamesqo, Did you find any solution for this issue?
I got a similar error message.

Eslint version: v5.4.0

@AntonioTsai @jamesqo Did you find out?

I think this is expected behavior. It doesn’t look like Flow supports default exports of types or interfaces. See the bottom of this page for more details.

You can still export the interface, it just has to be named.

It is a reserved keyword, but one who uses Typescript. What’s the solution esp. when eslint runs on pre-commit.

From the documentation linked above it looks like export default interface <> isn’t valid Flow syntax, and so can’t be used with Flow. You’re correct that it is valid in TypeScript though (see microsoft/TypeScript@5ef6192).

I believe the easiest workaround would be to export the interface as a named export.

Thank you for the issue. Now that @babel/eslint-parser has been released, we are making this repository read-only. If this is a change you would still like to advocate for, please reopen this in the babel/babel monorepo.

© 2023 GitHub, Inc.

You can’t perform that action at this time.

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.

Источник

ERROR: Parsing error: The keyword ‘const’ is reserved #14966

Prerequisites

  • [ yes] Can you reproduce the problem with Debug -> Reload Without Extensions ?
  • [yes] Did you perform a cursory search to see if your bug or enhancement is already reported?
  • [yes ] Did you read the Troubleshooting guide?
    I change the «brackets-eslint.useLocalESLint»: false, to true in preferences as suggested here:

Expected an identifier and instead saw ‘const’ — Stopping (. % scanned) #11632
Then restarted brackets

For more information on how to write a good bug report read here
For more information on how to contribute read here

Description

ERROR: Parsing error: The keyword ‘const’ is reserved
[Description of the bug or feature]
Unable to continue

Steps to Reproduce

  1. [First Step]
  2. [Second Step]
  3. [and so on. ]

Expected behavior: [What you expected to happen]
No error
Actual behavior: [What actually happened]
ERROR: Parsing error: The keyword ‘const’ is reserved const = require (‘electron’)

Versions

Please include the OS and what version of the OS you’re running.
Ubuntu 18.04 with xubuntu desktop
Please include the version of Brackets. You can find it under Help -> About Brackets (Windows and Linux) or Brackets -> About Brackets (macOS)
Release 1.14 build 1.14.0-17740 (release 329d08f)

The text was updated successfully, but these errors were encountered:

Источник

Parsing error: The keyword ‘const’ is reserved #28

Not sure why but somehow it started giving me this error.
I have es6: true in my .eslintrc.js
Running eslint from command line works fine and setting env inline in the file also works

any ideas on how to fix or debug?
I tried: reinstall (hence how I found the registry error ;)), using root: true , using old .eslintrc

The text was updated successfully, but these errors were encountered:

@AdriVanHoudt if brackets-eslint founds an eslint in your project (https://github.com/zaggino/brackets-eslint/blob/master/domain.js#L62) then it’ll use that version and version installed by npm-registry won’t matter. Check your project if you don’t have an old version of eslint maybe?

it is missing the config file? (version is fine btw)

When useEslintrc: true you shouldn’t need to specify path to config file. I use this extension across about 8-10 projects daily with different configs and it works fine, most of them use const too. But feel free to experiment, maybe you ran into some edge case or something.

yeah I have used it too across many different projects, it somehow broke for some reason 🙁

If I check here: http://eslint.org/docs/user-guide/configuring
With latest eslint, it should be «ecmaVersion»: 6, and not es6: true ?

Does your project work fine if you check it using eslint 2.7.0 from command line? Without Brackets?

es6: true is still a thing, tried with ecmaVersion but no difference, I made a new js file and it does not lint with my config at all

yes it works with running eslint . in project root

I’m guessing it’s not something you have lying around publicly on github? 🙂

the project or config?

also switched to another project with it’s own eslintrc and that uses const and no error, switch back, const error gone but now complains about default rules (like indents), owke.

well, the whole repo with config . or at least a config with a file which replicates the problem when I fetch it

Источник

Parsing error: The keyword ‘export’ is reserved #1464

What code were you trying to parse?

I’m trying to use typescript-eslint , and I followed the Getting Started page. Unfortunately, I’m having problems to make the parser identify very basic TypeScript/JS keywords, like export .

Please see https://github.com/flisboac/ts-promise-scheduler for the project in question. The error is:

My .eslint.js is configured as such:

And here are the first lines of the affected file

What did you expect to happen?

To accept export as a keyword, as per named/default export in TypeScript and the ES6+ standards, in the context of exporting declarations.

What actually happened?

export seems to be identified as a reserved name, regardless of context. Parsing fails.

Versions

Disclaimer:I’m using yarn .

package version
@typescript-eslint/parser 2.16.0
TypeScript 3.7.4
ESLint 6.8.0
node 12.13.0
npm 6.12.0
yarn 1.21.1

Output of yarn versions`:

Output of yarn list :

The text was updated successfully, but these errors were encountered:

Источник

Я получаю эту ошибку от ESLint:

error  Parsing error: The keyword 'const' is reserved

Из этого кода:

const express = require('express');
const app = express();
const _ = require('underscore');

Я попытался удалить node_modules и переустановить все пакеты npm (как было предложено здесь), но безрезультатно.

6 ответов

Лучший ответ

По умолчанию ESLint проверяет синтаксис ES5. Вы захотите переопределить последнюю поддерживаемую версию JavaScript.

Попробуйте добавить файл .eslintrc в ваш проект. Внутри него:

{
    "parserOptions": {
        "ecmaVersion": 2017
    },

    "env": {
        "es6": true
    }
}

Надеюсь, это поможет.

РЕДАКТИРОВАТЬ: я также нашел этот пример .eslintrc, который может помочь.


272

MultiplyByZer0
14 Окт 2018 в 16:22

Вы также можете добавить это встроенное вместо конфигурации, просто добавьте его в тот же файл, прежде чем добавлять свои собственные отключить вещи

/* eslint-env es6 */
/* eslint-disable no-console */

Мой случай был отключить файл и eslint-disable не работали только для меня

/* eslint-env es6 */
/* eslint-disable */


5

yousef
21 Ноя 2018 в 21:32

У меня была такая же проблема с этой частью моего кода:

const newComment = {
    dishId: dishId,
    rating: rating,
    author: author,
    comment: comment
};
newComment.date = new Date().toISOString();

Та же ошибка, const — зарезервированное слово.

Дело в том, что я сделал .eslintrc.js по ссылке, которую вы дали в обновлении, и все еще получил ту же ошибку. Кроме того, я получаю ошибку разбора в .eslintrc.js: Unexpected token ':'.

Прямо в этой части:

"env": {
"browser": true,
"node": true,
"es6": true
},

...


3

DarkSuniuM
14 Окт 2018 в 00:49

Если вы используете визуальный код, можно добавить это в файл settings.json:

"eslint.options": {
    "useEslintrc": false,
    "parserOptions": {
        "ecmaVersion": 2017
    },
    "env": {
        "es6": true
    }
}


1

Bjørnar Hvidsten
25 Ноя 2019 в 17:32

В моем случае не удалось найти файл .eslintrc, поэтому я скопировал его из node_modules / .bin в корневой каталог.


0

fuddin
8 Янв 2020 в 17:28

Я использовал .eslintrc.js и добавил следующий код.

module.exports = {
    "parserOptions": {
        "ecmaVersion": 6
    }
};


8

Khachornchit Songsaen
17 Июн 2018 в 09:34

Понравилась статья? Поделить с друзьями:
  • The game crashed whilst initializing game error java lang outofmemoryerror java heap space
  • The following components are required to run this program directx runtime как исправить на русском
  • The following components are required to run this program directx runtime как исправить windows 10
  • The following components are required to run this program directx runtime valorant как исправить
  • The filename directory name or volume label syntax is incorrect как исправить