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?
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.
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With