Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

create-react-app eslint error "Parsing error: 'import' and 'export' may appear only with 'sourceType: module'"

I have just created a new app using create-react app and eslint is giving me this error Parsing error: 'import' and 'export' may appear only with 'sourceType: module'

i am new to react and dont know what i am doing wrong, though the app is running fine I am using VS code editor. How to remove this problem?

like image 808
Akash Salunkhe Avatar asked Jul 21 '18 15:07

Akash Salunkhe


People also ask

How to configure ESLint in ReactJS?

The simplest way to configure ESLint using the below NPM commands To enable ESLint configurations extension in your react Application, install the extension in your favourite Editor, I recommend you to use vscode for better experience Create .eslintrc.js file in your project’s root folder and add the below text to that file.

What is ESLint-plugin-prettier?

Package eslint-plugin-react contains React specific ESLint rules, and eslint-plugin-prettier implements Prettier rules as ESLint ones. In the extends property we can specify one or more shareable ESLint configs that we want to apply.

Why is ESLint not working on my package?

If there is a .eslintrc and a package.json file found in the same directory, .eslintrc will take priority and package.json file will not be used. By default, ESLint will look for configuration files in all parent folders up to the root directory.

What configuration should I use for ESLint in JavaScript?

JavaScript (ESM) - use .eslintrc.cjs when running ESLint in JavaScript packages that specify "type":"module" in their package.json. Note that ESLint does not support ESM configuration at this time. YAML - use .eslintrc.yaml or .eslintrc.yml to define the configuration structure. JSON - use .eslintrc.json to define the configuration structure.


1 Answers

Try adding sourceType: "module" To the eslint configuration

// in .eslintrc.js (recommended) or .eslintrc (deprecated)
{
...
  "parserOptions": {
    ...
    "sourceType": "module"
    ...
  } 
...
}

https://eslint.org/docs/user-guide/configuring#specifying-parser-options

like image 169
Yossi Avatar answered Sep 20 '22 20:09

Yossi