In Visual Studio Code I get
Parsing error: The keyword 'import' is reserved
.
1
What actions would you recommend to remedy this error?
I provide my .eslintrc.json
and package.json
files below.
However, they will likely not be sufficient to reproduce the error.
So here is a link to
a zip file containing all the necessary project files.
2
The project is (locally) installed by running npm install
– this may
take about 5-9 minutes.
Then npm start
should open the project in the default web browser.
3
When I do this and hit F12, I get no errors but two warnings
in the console of the browser.
The warnings are:
'unUsedArgument' is defined but never used. Allowed unused args must match /^_/u no-unused-vars
, and'unUsedVariable' is assigned a value but never used. Allowed unused vars must match /^_/u no-unused-vars
.
The error in the title, Parsing error: The keyword 'import' is reserved
, shows up when I open App.js
in VS Code.
But this error has nothing to do with my choice of text editor,
which is easy to confirm by running ESLint from the command line.
4
node_modules/.bin/eslint . --ext .js
.eslintrc.json
:
{
"rules": {
"no-unused-vars": [
"warn",
{
"argsIgnorePattern": "^_",
"varsIgnorePattern": "^_"
}
]
}
}
package.json
:
{
"name": "parsing-error",
"version": "0.1.0",
"dependencies": {
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.4.1",
"@testing-library/user-event": "^7.2.1",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-scripts": "4.0.3"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version"
]
}
}
Visual Studio Code? – Other text editors or IDE:s?
Although I am using Visual Studio Code, I invite answers (and
discussions) of other text editors and IDE:s as well.
Note that – in addition to installing ESLint correctly via npm
– you
also have to install a plugin/extension for your specific
integrated development environment (IDE).
In my case, I use this VS Code ESLint extension.
5
Still, the focus here should clearly be on the npm
command and on the
Node.js packages installed.
Previous reports of the error
In references 5-12 of the list below, I link some previous reports
of this error – or similar errors.
Some of those links (questions) are clearly related to the issue here,
but maybe not all of them.
References
- Zip file containing the needed project files
- To install ESLint globally rather than locally (using
npm install eslint --global
) is not recommended - VS Code ESLint extension
- In VS Code, add
"eslint.nodePath": "C:\\Program Files\\nodejs",
tosettings.json
- Parsing error: The keyword 'export' is reserved
- Parsing error: The keyword 'import' is reserved
- ERROR: Parsing Error: The keyword 'const' is reserved
- eslint: error Parsing error: The keyword 'const' is reserved
- Parsing Error The Keyword import is Reserved (SublimeLinter-...)
- Setting up Airbnb ESLint with React and Webpack
- Parsing error: The keyword 'enum' is reserved
- ESLint Parsing error: Unexpected token
1 The word import
could be const
– or just about any
other JavaScript keyword.
2 Since it is recommended to install ESLint locally, I assume all readers here do so.
3 In my case Google Chrome Version 98.0.4758.102, 64-bit. Running on Windows 10.
4 If you are on Microsoft Windows (like myself), use
backward slashes instead of forward slashes, like so:node_modules\.bin\eslint . --ext .js
5 Apart from installing the extension, I have added
"eslint.nodePath": "C:\\Program Files\\nodejs",
to my (user) settings.json
file in VS Code. No other changes.