简体   繁体   English

错误:找不到模块“eslint-config-flowtype”

[英]Error: Cannot find module 'eslint-config-flowtype'

I'm trying to use Webpack, ESLint and Flow type altogether.我正在尝试完全使用 Webpack、ESLint 和 Flow 类型。 But, when I start webpack-dev-server I get the error message below.但是,当我启动 webpack-dev-server 时,我收到以下错误消息。 The weird thing is that eslint-config-flowtype is not even a module in NPM.奇怪的是eslint-config-flowtype甚至不是 NPM 中的一个模块。 Has someone encountered this issue before?以前有人遇到过这个问题吗? Thanks in advance!提前致谢!

ERROR in ./src/index.jsx
Module build failed (from ./node_modules/eslint-loader/index.js):
Error: Cannot find module 'eslint-config-flowtype'
Referenced from: /Users/crs/code/my-project/.eslintrc.json
    at ModuleResolver.resolve (/Users/crs/code/react-builerplate/node_modules/eslint/lib/util/module-resolver.js:74:19)
    at resolve (/Users/crs/code/react-builerplate/node_modules/eslint/lib/config/config-file.js:479:28)
    at load (/Users/crs/code/react-builerplate/node_modules/eslint/lib/config/config-file.js:551:26)
    at configExtends.reduceRight (/Users/crs/code/react-builerplate/node_modules/eslint/lib/config/config-file.js:425:36)
    at Array.reduceRight (<anonymous>)
    at applyExtends (/Users/crs/code/react-builerplate/node_modules/eslint/lib/config/config-file.js:403:26)
    at loadFromDisk (/Users/crs/code/react-builerplate/node_modules/eslint/lib/config/config-file.js:523:22)
    at Object.load (/Users/crs/code/react-builerplate/node_modules/eslint/lib/config/config-file.js:559:20)
    at Config.getLocalConfigHierarchy (/Users/crs/code/react-builerplate/node_modules/eslint/lib/config.js:227:44)
    at Config.getConfigHierarchy (/Users/crs/code/react-builerplate/node_modules/eslint/lib/config.js:179:43)
 @ multi (webpack)-dev-server/client?http://localhost:8000 webpack/hot/dev-server react-hot-loader/patch webpack-dev-server/client?http://localhost:8080 webpack/hot/only-dev-server ./src/index.jsx

Below are all my project's dependencies:以下是我项目的所有依赖项:

  "dependencies": {
    "axios": "0.16.1",
    "babel-plugin-dynamic-import-webpack": "1.0.1",
    "babel-plugin-transform-decorators-legacy": "1.3.4",
    "babel-register": "6.24.1",
    "compression": "1.6.2",
    "cors": "2.8.3",
    "express": "4.15.3",
    "lodash": "4.17.4",
    "preact": "8.1.0",
    "preact-compat": "3.16.0",
    "prop-types": "^15.6.1",
    "prop-types-extra": "^1.1.0",
    "react": "^16.4.0",
    "react-addons-perf": "^15.4.2",
    "react-dom": "^16.4.0",
    "react-hot-loader": "3.0.0-beta.6",
    "react-redux": "^5.0.7",
    "react-router-dom": "^4.3.1",
    "redux": "^4.0.0",
    "redux-thunk": "^2.3.0",
    "styled-components": "^3.3.2",
    "webpack": "^4.11.1",
    "webpack-dev-middleware": "1.10.2",
    "webpack-hot-middleware": "2.18.0"
  },
  "devDependencies": {
    "babel-core": "6.24.1",
    "babel-eslint": "^8.2.3",
    "babel-loader": "^7.1.4",
    "babel-plugin-dynamic-import-node": "1.0.2",
    "babel-plugin-react-flow-props-to-prop-types": "^0.15.0",
    "babel-plugin-syntax-dynamic-import": "6.18.0",
    "babel-plugin-transform-class-properties": "6.24.1",
    "babel-plugin-transform-es2015-modules-commonjs": "6.24.1",
    "babel-preset-env": "1.5.1",
    "babel-preset-flow": "^6.23.0",
    "babel-preset-react": "6.24.1",
    "enzyme": "2.8.2",
    "eslint": "^4.19.1",
    "eslint-config-airbnb": "^16.1.0",
    "eslint-config-prettier": "^2.9.0",
    "eslint-config-react": "1.1.7",
    "eslint-loader": "^2.0.0",
    "eslint-plugin-flow": "2.29.1",
    "eslint-plugin-flowtype": "^2.49.3",
    "eslint-plugin-import": "^2.7.0",
    "eslint-plugin-jsx-a11y": "^6.0.3",
    "eslint-plugin-prettier": "^2.6.0",
    "eslint-plugin-react": "^7.1.0",
    "flow-bin": "^0.74.0",
    "husky": "^0.14.3",
    "jest": "20.0.4",
    "jest-serializer-enzyme": "1.0.0",
    "lint-staged": "^7.1.3",
    "moxios": "0.4.0",
    "nodemon": "1.11.0",
    "prettier": "^1.13.5",
    "prettier-eslint": "^8.8.1",
    "react-test-renderer": "15.5.4",
    "webpack-cli": "^3.0.3",
    "webpack-dev-server": "^3.1.4",
    "webpack-serve": "^1.0.3"
  }

.eslintrc.json .eslintrc.json

{
  "parser": "babel-eslint",
  "extends": [
    "flowtype",
    "plugin:flowtype/recommended",
    "airbnb",
    "prettier",
    "prettier/react"
  ],
  "plugins": [
    "prettier"
  ],
  "parserOptions": {
    "ecmaVersion": 2016,
    "sourceType": "module",
    "ecmaFeatures": {
      "jsx": true
    }
  },
  "env": {
    "es6": true,
    "browser": true,
    "node": true
  },
  "rules": {
    "prettier/prettier": "error",
    "flowtype/boolean-style": [
      2,
      "boolean"
    ],
    "flowtype/define-flow-type": 1,
    "flowtype/delimiter-dangle": [
      2,
      "never"
    ],
    "flowtype/generic-spacing": [
      2,
      "never"
    ],
    "flowtype/no-primitive-constructor-types": 2,
    "flowtype/no-types-missing-file-annotation": 2,
    "flowtype/no-weak-types": 2,
    "flowtype/object-type-delimiter": [
      2,
      "comma"
    ],
    "flowtype/require-parameter-type": 2,
    "flowtype/require-return-type": [
      2,
      "always",
      {
        "annotateUndefined": "never"
      }
    ],
    "flowtype/require-valid-file-annotation": 2,
    "flowtype/semi": [
      2,
      "always"
    ],
    "flowtype/space-after-type-colon": [
      2,
      "always"
    ],
    "flowtype/space-before-generic-bracket": [
      2,
      "never"
    ],
    "flowtype/space-before-type-colon": [
      2,
      "never"
    ],
    "flowtype/type-id-match": [
      2,
      "^([A-Z][a-z0-9]+)+Type$"
    ],
    "flowtype/union-intersection-spacing": [
      2,
      "always"
    ],
    "flowtype/use-flow-type": 1,
    "flowtype/valid-syntax": 1
  },
  "settings": {
    "flowtype": {
      "onlyFilesWithFlowAnnotation": false
    }
  }
}

In order to configure flowType with your ESlint, you need to configure it like为了用你的 ESlint 配置 flowType,你需要像这样配置它

 "extends": [
    "plugin:flowtype/recommended",
    "airbnb",
    "prettier",
    "prettier/react"
  ],
  "plugins": [
    "prettier",
    "flowtype"
  ]

For more details check this documentation有关更多详细信息,请查看此文档

Got a similar error in Visual Studio using Create React App but it was:使用 Create React App 在 Visual Studio 中遇到了类似的错误,但它是:

(ESLint) Failed to load plugin 'flowtype' declared in 'package.json » eslint-config-react-app': Cannot find module 'eslint-plugin-flowtype (ESLint)无法加载在“package.json»eslint-config-react-app”中声明的插件“flowtype”:找不到模块“eslint-plugin-flowtype”

在此处输入图片说明

Solved by installing it as a global package: npm i -g eslint-plugin-flowtype通过将其安装为全局包来解决: npm i -g eslint-plugin-flowtype

More info here:更多信息在这里:

https://github.com/facebook/create-react-app/issues/274 https://github.com/facebook/create-react-app/issues/274

https://github.com/eslint/eslint/issues/3458 https://github.com/eslint/eslint/issues/3458

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法加载在“package.json » eslint-config-react-app”中声明的插件“flowtype”:找不到模块“eslint/use-at-your-own-risk” - Failed to load plugin 'flowtype' declared in 'package.json » eslint-config-react-app': Cannot find module 'eslint/use-at-your-own-risk' Atom &amp; eslint:找不到模块 'eslint-config-react-app' - Atom & eslint: Cannot find module 'eslint-config-react-app' (ESLint)在VS 2017 react项目中找不到模块&#39;eslint-config-react-app&#39; - (ESLint) Cannot find module 'eslint-config-react-app' in VS 2017 react project 错误:找不到模块“eslint/lib/rules/no-unused-expressions” - Error: Cannot find module 'eslint/lib/rules/no-unused-expressions' 使用eslint-config-airbnb ESLint“模块构建失败”错误 - ESLint “Module build failed” error with eslint-config-airbnb 处理“无法加载在‘.eslintrc’中声明的插件‘react’:找不到模块‘eslint-plugin-react’”ESLint 错误 - Dealing with "Failed to load plugin 'react' declared in '.eslintrc': Cannot find module 'eslint-plugin-react'" ESLint error ESLint 错误 - ESLint 找不到配置“react-app” - ESLint error - ESLint couldn't find the config "react-app" 错误:无法加载在“.eslintrc”中声明的解析器“babel-eslint”:在 create-react-app 中找不到模块“babel-eslint” - Error: Failed to load parser 'babel-eslint' declared in '.eslintrc': Cannot find module 'babel-eslint' in create-react-app Jest 找不到模块“配置” - Jest cannot find module 'config' 无法加载在 'package.json » eslint-config-react-app#overrides[0]' 中声明的解析器 '@typescript-eslint/parser':找不到模块 'typescript' - Failed to load parser '@typescript-eslint/parser' declared in 'package.json » eslint-config-react-app#overrides[0]': Cannot find module 'typescript'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM