admin管理员组

文章数量:1417425

I was working on a new react project and had set up my ESlint which was running fine before I changed code in another file and now it's giving me an error:

Error: Unexpected token 'export'

I'm new to eslint and so I'm using all the default settings that are remended however I'm hesitant to post this just because I feel like this may be a formatting error on my part. Any help would be greatly appreciated.

Here is my ESlint file:

export default{
    "env": {
        "browser": true,
        "es2021": true
    },
    "extends": [
        "eslint:remended",
        "plugin:react/remended"
    ],
    "parserOptions": {
        "ecmaFeatures": {
            "jsx": true
        },
        "ecmaVersion": 12,
        "sourceType": "module"
    },
    "plugins": [
        "react"
    ],
    "rules": {
        "no-extra-semi":"error"

    }
    
};

and here is the Package's json:

{
  "name": "testapp",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^5.12.0",
    "@testing-library/react": "^11.2.6",
    "@testing-library/user-event": "^12.8.3",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-scripts": "4.0.3",
    "web-vitals": "^1.1.1"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "devDependencies": {
    "eslint": "^7.25.0",
    "eslint-plugin-react": "^7.23.2"
  }
}

any help is very appreciated

I was working on a new react project and had set up my ESlint which was running fine before I changed code in another file and now it's giving me an error:

Error: Unexpected token 'export'

I'm new to eslint and so I'm using all the default settings that are remended however I'm hesitant to post this just because I feel like this may be a formatting error on my part. Any help would be greatly appreciated.

Here is my ESlint file:

export default{
    "env": {
        "browser": true,
        "es2021": true
    },
    "extends": [
        "eslint:remended",
        "plugin:react/remended"
    ],
    "parserOptions": {
        "ecmaFeatures": {
            "jsx": true
        },
        "ecmaVersion": 12,
        "sourceType": "module"
    },
    "plugins": [
        "react"
    ],
    "rules": {
        "no-extra-semi":"error"

    }
    
};

and here is the Package's json:

{
  "name": "testapp",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^5.12.0",
    "@testing-library/react": "^11.2.6",
    "@testing-library/user-event": "^12.8.3",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-scripts": "4.0.3",
    "web-vitals": "^1.1.1"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "devDependencies": {
    "eslint": "^7.25.0",
    "eslint-plugin-react": "^7.23.2"
  }
}

any help is very appreciated

Share Improve this question asked May 8, 2021 at 14:23 William AddisonWilliam Addison 911 silver badge4 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 1

fix mine by replacing

export default {}

with

module.exports = {}

An error may occur due to the format of the ESLint configuration file.

To export CommonJS:

//eslint.config.cjs
module.exports = {}

For modular (ES6+) export:

//.eslintrc.js
export default []

Example for JSX-modules:

//eslint.config.js
export default [{
  languageOptions: {
    parserOptions: {
      ecmaFeatures: {
        jsx: true,
        modules: true,
      },
    },
  },
}]

本文标签: javascriptReact Project ESlint error quotUnexpected Token ExportquotStack Overflow