create-react-app eslint 错误“解析错误:‘import’和‘export’可能只出现在‘sourceType:module’中”

Aka*_*khe 5 javascript reactjs eslint

我刚刚使用 create-react app 创建了一个新应用程序,eslint 给了我这个错误解析错误:'import' 和 'export' 可能只出现在 'sourceType: module'

我是新手,不知道我做错了什么,虽然应用程序运行良好,但我使用的是 VS 代码编辑器。如何消除这个问题?

Yos*_*ssi 10

尝试添加 sourceType: "module" 到 eslint 配置

// in .eslintrc.js (recommended) or .eslintrc (deprecated)
{
...
  "parserOptions": {
    ...
    "sourceType": "module"
    ...
  } 
...
}
Run Code Online (Sandbox Code Playgroud)

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

  • 你能告诉我到底要添加到哪里吗 ie eslint 配置文件在哪里 (2认同)