Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 带Babel、Flow、React和React Native的ESLint配置_Reactjs_React Native_Eslint_Flowtype_Prettier - Fatal编程技术网

Reactjs 带Babel、Flow、React和React Native的ESLint配置

Reactjs 带Babel、Flow、React和React Native的ESLint配置,reactjs,react-native,eslint,flowtype,prettier,Reactjs,React Native,Eslint,Flowtype,Prettier,我正在用React Native开发一个移动应用程序,我已经尝试了一段时间正确配置ESLint(包括Babel、Flow和Prettier) 我在VSCode中遇到以下错误:“模块”应该列在项目的依赖项中。eslint(导入/无无关依赖项)。 这适用于我的所有模块和插件,如react、react native和其他。我安装了每个包和VSCode ESLint扩展,但ESLint仍然会引发此错误。也许我也复制了extends部分中的一些功能,我想知道我的配置是否良好,以及我是否可以消除这个错误(其

我正在用React Native开发一个移动应用程序,我已经尝试了一段时间正确配置ESLint(包括Babel、Flow和Prettier)

我在VSCode中遇到以下错误:
“模块”应该列在项目的依赖项中。eslint(导入/无无关依赖项)
。 这适用于我的所有模块和插件,如react、react native和其他。我安装了每个包和VSCode ESLint扩展,但ESLint仍然会引发此错误。也许我也复制了
extends
部分中的一些功能,我想知道我的配置是否良好,以及我是否可以消除这个错误(其他一切看起来都正常工作)

.eslintrc.json

{
  "extends": [
    "airbnb",
    "plugin:react/recommended",
    "plugin:flowtype/recommended",
    "plugin:prettier/recommended",
    "prettier",
    "prettier/babel",
    "prettier/react",
    "prettier/flowtype",
    "prettier/standard"
  ],
  "plugins": [
    "react",
    "react-native",
    "flowtype",
    "standard",
    "prettier"
  ],
  "parser": "babel-eslint",
  "parserOptions": {
    "ecmaVersion": 6,
    "sourceType": "module",
    "ecmaFeatures": {
      "jsx": true,
      "modules": true
    }
  },
  "env": {
    "browser": true,
    "jest": true
  },
  "rules": {
    "import/no-unresolved": "off",
    "react/jsx-filename-extension": [
      1,
      {
        "extensions": [
          ".js",
          ".jsx"
        ]
      }
    ],
    "prettier/prettier": [
      "error",
      {
        "trailingComma": "es5",
        "singleQuote": true,
        "printWidth": 100
      }
    ]
  }
}
{
  "name": "PICSTART",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "ios": "react-native run-ios --simulator=\"iPhone XR\"",
    "android": "react-native run-android",
    "debugjs": "react-devtools",
    "test": "jest",
    "flow": "node_modules/flow-bin/vendor/flow"
  },
  "dependencies": {
    "@okgrow/react-native-copilot": "^2.4.1",
    "moment": "^2.24.0",
    "react": "16.5.0",
    "react-native": "0.57.1",
    "react-native-camera": "^1.3.0",
    "react-native-datepicker": "^1.7.2",
    "react-native-fs": "^2.13.3",
    "react-native-image-picker": "^0.28.0",
    "react-native-loading-spinner-overlay": "^1.0.1",
    "react-native-modal": "^9.0.0",
    "react-native-svg": "^9.3.3",
    "react-native-vector-icons": "^6.1.0",
    "react-navigation": "^2.0.4",
    "react-redux": "^5.0.7",
    "redux": "^4.0.0",
    "redux-mock-store": "^1.5.1",
    "redux-thunk": "^2.3.0"
  },
  "devDependencies": {
    "@babel/core": "^7.1.2",
    "@babel/runtime": "^7.1.2",
    "babel-eslint": "^10.0.1",
    "babel-jest": "23.6.0",
    "eslint": "^5.15.3",
    "eslint-config-airbnb": "^17.1.0",
    "eslint-config-prettier": "^4.1.0",
    "eslint-plugin-flowtype": "^3.4.2",
    "eslint-plugin-import": "^2.16.0",
    "eslint-plugin-jsx-a11y": "^6.2.1",
    "eslint-plugin-prettier": "^3.0.1",
    "eslint-plugin-react": "^7.12.4",
    "eslint-plugin-react-native": "^3.6.0",
    "eslint-plugin-standard": "^4.0.0",
    "flow-bin": "^0.78.0",
    "jest": "23.6.0",
    "metro-react-native-babel-preset": "0.47.0",
    "prettier": "^1.16.4",
    "react-test-renderer": "16.5.0"
  },
  "jest": {
    "preset": "react-native",
    "testRegex": "./__tests__/[^setup].*.js$",
    "transformIgnorePatterns": [
      "node_modules/(?!react-native|native-base|react-navigation|react-native-fabric)"
    ],
    "setupFiles": [
      "./__tests__/setup.js"
    ]
  }
}
package.json

{
  "extends": [
    "airbnb",
    "plugin:react/recommended",
    "plugin:flowtype/recommended",
    "plugin:prettier/recommended",
    "prettier",
    "prettier/babel",
    "prettier/react",
    "prettier/flowtype",
    "prettier/standard"
  ],
  "plugins": [
    "react",
    "react-native",
    "flowtype",
    "standard",
    "prettier"
  ],
  "parser": "babel-eslint",
  "parserOptions": {
    "ecmaVersion": 6,
    "sourceType": "module",
    "ecmaFeatures": {
      "jsx": true,
      "modules": true
    }
  },
  "env": {
    "browser": true,
    "jest": true
  },
  "rules": {
    "import/no-unresolved": "off",
    "react/jsx-filename-extension": [
      1,
      {
        "extensions": [
          ".js",
          ".jsx"
        ]
      }
    ],
    "prettier/prettier": [
      "error",
      {
        "trailingComma": "es5",
        "singleQuote": true,
        "printWidth": 100
      }
    ]
  }
}
{
  "name": "PICSTART",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "ios": "react-native run-ios --simulator=\"iPhone XR\"",
    "android": "react-native run-android",
    "debugjs": "react-devtools",
    "test": "jest",
    "flow": "node_modules/flow-bin/vendor/flow"
  },
  "dependencies": {
    "@okgrow/react-native-copilot": "^2.4.1",
    "moment": "^2.24.0",
    "react": "16.5.0",
    "react-native": "0.57.1",
    "react-native-camera": "^1.3.0",
    "react-native-datepicker": "^1.7.2",
    "react-native-fs": "^2.13.3",
    "react-native-image-picker": "^0.28.0",
    "react-native-loading-spinner-overlay": "^1.0.1",
    "react-native-modal": "^9.0.0",
    "react-native-svg": "^9.3.3",
    "react-native-vector-icons": "^6.1.0",
    "react-navigation": "^2.0.4",
    "react-redux": "^5.0.7",
    "redux": "^4.0.0",
    "redux-mock-store": "^1.5.1",
    "redux-thunk": "^2.3.0"
  },
  "devDependencies": {
    "@babel/core": "^7.1.2",
    "@babel/runtime": "^7.1.2",
    "babel-eslint": "^10.0.1",
    "babel-jest": "23.6.0",
    "eslint": "^5.15.3",
    "eslint-config-airbnb": "^17.1.0",
    "eslint-config-prettier": "^4.1.0",
    "eslint-plugin-flowtype": "^3.4.2",
    "eslint-plugin-import": "^2.16.0",
    "eslint-plugin-jsx-a11y": "^6.2.1",
    "eslint-plugin-prettier": "^3.0.1",
    "eslint-plugin-react": "^7.12.4",
    "eslint-plugin-react-native": "^3.6.0",
    "eslint-plugin-standard": "^4.0.0",
    "flow-bin": "^0.78.0",
    "jest": "23.6.0",
    "metro-react-native-babel-preset": "0.47.0",
    "prettier": "^1.16.4",
    "react-test-renderer": "16.5.0"
  },
  "jest": {
    "preset": "react-native",
    "testRegex": "./__tests__/[^setup].*.js$",
    "transformIgnorePatterns": [
      "node_modules/(?!react-native|native-base|react-navigation|react-native-fabric)"
    ],
    "setupFiles": [
      "./__tests__/setup.js"
    ]
  }
}
此错误
eslint(导入/无无关依赖项)
发生的原因是您导入的模块不在
package.json中。

如果一切正常,编译时没有错误,您可以查看,并解释如何禁用此规则

如果
.eslintrc.json
package.json
不在同一个文件夹中,这可能会导致错误,因为eslint查找
package.json
文件,但它可以找到它,因为它位于另一个文件夹中

编辑:可能您在
“env”

试一试

此错误
eslint(导入/无无关依赖项)
发生的原因是您导入的模块不在
package.json中。

如果一切正常,编译时没有错误,您可以查看,并解释如何禁用此规则

如果
.eslintrc.json
package.json
不在同一个文件夹中,这可能会导致错误,因为eslint查找
package.json
文件,但它可以找到它,因为它位于另一个文件夹中

编辑:可能您在
“env”

试一试


你查了什么?这对您来说意味着什么?我检查了my.eslintrc.json和package.json是否都在根文件夹中。我也看到了这个规则,但我不想禁用对已安装软件包的检查,这个解决方案更像是一个解决方案。它应该能够工作…请提供更多关于您的项目的信息,我不知道如何解决这个问题,只有与该信息。导入*作为反应从'反应';从“react native”导入{Image};这种导入会引起错误。我还能分享什么?不,没有任何改变你查了什么?这对您来说意味着什么?我检查了my.eslintrc.json和package.json是否都在根文件夹中。我也看到了这个规则,但我不想禁用对已安装软件包的检查,这个解决方案更像是一个解决方案。它应该能够工作…请提供更多关于您的项目的信息,我不知道如何解决这个问题,只有与该信息。导入*作为反应从'反应';从“react native”导入{Image};这种导入会引起错误。我还能分享什么?不,不会改变任何事情