English 中文(简体)
为什么进口/无极端依赖的ESLint 旧包裹的失败?
原标题:Why (and How Can I FIx) ESLint import/no-extraneous-dependencies Failures on Installed Packages?

When I run ESLint I get the following errors:

1:13  error   joi  should be listed in the project s dependencies. Run  npm i -S joi  to add it        import/no-extraneous-dependencies
2:16  error   lodash  should be listed in the project s dependencies. Run  npm i -S lodash  to add it  import/no-extraneous-dependencies

然而,我已安装了这两个单元,并载于我的<编码> 包装.json:

"joi": "^10.4.2",
"lodash": "^4.17.2",

and running npm i -S joi doesn t help or fix the issue. I have tons of other packages in my package.json, and only those two have issues.

The s possible that this is a bug, but ESLint has so many he on it 我认为,Im做一些错事的可能性更大,但我只能指出什么(这些包裹与我的 Package.json中的任何其他内容一样)。

没有人会说,我(无意中)可以做些什么,就这两份一揽子计划提出ESLint申诉,而只有这两项一揽子计划,尽管它们已经安装?


这里有我的<条码>包装,json,其中删除了几个与识别符号无关之处:

{
  "name": "foo",
  "version": "1.0.0",
  "engines": {
    "node": "6.9.4"
  },
  "scripts": {
    "some": "scripts",
  },
  "ava": {
    "babel": "inherit",
    "require": "babel-register",
    "serial": true,
    "verbose": true
  },
  "devDependencies": {
    "@3846masa/axios-cookiejar-support": "0.0.4",
    "apidoc": "^0.17.5",
    "ava": "^0.17.0",
    "babel-eslint": "^7.1.1",
    "babel-plugin-module-alias": "^1.6.0",
    "babel-react-render-defender": "^1.1.1",
    "chai": "^3.5.0",
    "chai-enzyme": "^0.6.1",
    "del": "^2.2.2",
    "enzyme": "^2.6.0",
    "eslint": "^3.19.0",
    "eslint-config-airbnb": "^13.0.0",
    "eslint-import-resolver-babel-module": "^3.0.0",
    "eslint-plugin-babel": "^4.0.0",
    "eslint-plugin-import": "^2.2.0",
    "eslint-plugin-jsx-a11y": "^2.2.3",
    "eslint-plugin-react": "^6.8.0",
    "jsdom": "^9.9.1",
    "nodemon": "^1.11.0",
    "proxyquire": "^1.7.10",
    "react-addons-test-utils": "^15.4.1",
    "react-hot-loader": "^3.0.0-beta.6",
    "really-need": "^1.9.2",
    "redux-devtools-extension": "^1.0.0",
    "s3rver": "^1.0.2",
    "sinon": "^1.17.6",
    "style-loader": "^0.13.1",
    "supertest": "^2.0.1"
  },
  "dependencies": {
    "autoprefixer": "^6.5.4",
    "ava": "^0.17.0",
    "aws-sdk": "^2.7.21",
    "axios": "^0.15.3",
    "babel-core": "^6.20.0",
    "babel-loader": "^6.2.9",
    "babel-plugin-lodash": "^3.2.11",
    "babel-plugin-module-resolver": "^2.5.0",
    "babel-plugin-transform-decorators-legacy": "^1.3.4",
    "babel-plugin-transform-object-rest-spread": "^6.22.0",
    "babel-plugin-transform-runtime": "^6.15.0",
    "babel-preset-decorators-legacy": "^1.0.0",
    "babel-preset-es2015": "^6.18.0",
    "babel-preset-react": "^6.16.0",
    "babel-runtime": "^6.20.0",
    "bluebird": "^3.4.6",
    "body-parser": "^1.17.1",
    "celebrate": "^4.0.0",
    "chai-diff": "^1.0.1",
    "classnames": "^2.2.5",
    "clipboard": "^1.6.1",
    "compression": "^1.6.2",
    "cookie-parser": "^1.4.3",
    "cookie-session": "^2.0.0-alpha.2",
    "core-decorators": "^0.15.0",
    "csrf": "^3.0.6",
    "css-mqpacker": "^5.0.1",
    "cssnano": "^3.9.1",
    "debug": "^2.6.0",
    "dotenv": "^2.0.0",
    "express": "^4.14.0",
    "express-sanitizer": "^1.0.2",
    "extract-text-webpack-plugin": "^1.0.1",
    "faker": "^3.1.0",
    "feedparser": "^2.0.0",
    "file-loader": "^0.10.0",
    "flatpickr": "^2.6.1",
    "helmet": "^3.5.0",
    "html-webpack-plugin": "^2.28.0",
    "immutability-helper": "^2.1.1",
    "joi": "^10.4.1",
    "js-cookie": "^2.1.3",
    "json-loader": "^0.5.4",
    "jsonp-promise": "^0.1.2",
    "knex": "0.12.9",
    "libxmljs": "^0.18.4",
    "lodash": "^4.17.2",
    "lodash-webpack-plugin": "^0.11.0",
    "moment": "^2.18.1",
    "morgan": "^1.7.0",
    "node-fetch": "^1.6.3",
    "pg": "^6.1.2",
    "plist": "^2.0.1",
    "postcss": "^5.2.6",
    "postcss-custom-media": "^5.0.1",
    "postcss-custom-properties": "^5.0.1",
    "postcss-import": "^9.0.0",
    "postcss-loader": "^1.2.1",
    "raw-loader": "^0.5.1",
    "rc-time-picker": "^2.3.3",
    "react": "^15.4.1",
    "react-addons-shallow-compare": "^15.4.2",
    "react-dnd": "^2.2.3",
    "react-dnd-html5-backend": "^2.2.3",
    "react-dom": "^15.4.1",
    "react-flatpickr": "^3.3.0",
    "react-json-tree": "^0.10.1",
    "react-modal": "^1.6.5",
    "react-redux": "^5.0.0",
    "react-router": "^3.0.0",
    "react-router-redux": "^4.0.7",
    "react-sortable-hoc": "^0.6.1",
    "react-virtualized": "^8.11.4",
    "recompose": "^0.23.1",
    "redux": "^3.6.0",
    "redux-actions": "^1.2.0",
    "redux-debounce": "^1.0.1",
    "redux-logger": "^2.7.4",
    "redux-promise": "^0.5.3",
    "redux-thunk": "^2.1.0",
    "reselect": "^2.5.4",
    "stylelint": "^7.7.0",
    "svg-react-loader": "^0.4.0-beta.2",
    "svgo": "^0.7.1",
    "to-exports": "^0.1.0",
    "twit": "^2.2.5",
    "url-loader": "^0.5.7",,
    "webpack": "^1.14.0",
    "webpack-dev-middleware": "^1.8.4",
    "webpack-hot-middleware": "^2.15.0",
    "webpack-split-chunks": "^0.1.1",
    "xmlbuilder": "^8.2.2"
  }
}

你们可以看到,这只是简单明了的;只是许多一揽子计划。


参看我的<代码>。

{
  "extends": "airbnb",
  "env": {
    "browser": true,
    "node": true
  },
  "globals": {
    "NODE_ENV": true,
    "isProduction": true,
    "__ROUTE__": true
  },
  "parser": "babel-eslint",
  "plugins": [
    "babel"
  ],
  "rules": {
    "react/jsx-filename-extension": [
      "error",
      {
        "extensions": [
          ".js",
          ".jsx"
        ]
      }
    ],
    "comma-dangle": [
      "error",
      {
        "arrays": "always-multiline",
        "objects": "always-multiline",
        "imports": "always-multiline",
        "exports": "always-multiline",
        "functions": "ignore"
      }
    ],
    "eol-last": "error",
    "import/order": "error",
    "This next rule is just temporary until we start using PropTypes": 0,
    "react/prop-types": 0
  },
  "settings": {
    "import/resolver": {
      "babel-module": {}
    }
  }
}
最佳回答

在座各位面前添加以下内容,只是在那里有正确的规则。 是的,你也可以这样做,但错误是出于这种原因。

"import/no-extraneous-dependencies": ["error", {"devDependencies": false, "optionalDependencies": false, "peerDependencies": false}]

就我所知,你的一揽子计划没有任何问题。 json, 因此,它必须是一个yn子问题。

我没有你的法典,所以我要举几个例子:

var _ = require( lodash );
import _ from  lodash ;

如果您有上述法律(或类似法律)

然后改为:

import test from  ava ;
import find from  lodash.find ;

你可以在这里读得更多:

https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-extraneous-dependencies.md”rel=“noreferer”>https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-extraneous-dependencies.md

问题回答

If you arrived here while searching for Definition for rule import/no-extraneous-dependencies was not found

接着,为了确定这一问题,请在<代码>上添加“编码>”插图:“进口”。 档案

我有同样的问题。

对我来说,解决办法是增加一揽子方案。 迪尔方案明确规定:

"import/no-extraneous-dependencies": [
    "error", {
       "devDependencies": false, 
       "optionalDependencies": false, 
       "peerDependencies": false, 
       "packageDir": "./"
    }
]

我只是通过确定现实状况来解决。 否则就是虚假的。

"import/no-extraneous-dependencies": [
        "error", {
           "devDependencies": true
        }
    ]

<代码>残疾:包装材料或<编码>devDependencies:虚假上的解决办法给我带来了一定的工作,但最终我已经解决了这一问题。 在座各位:

"import/no-extraneous-dependencies": [
  "error",
  {
    "devDependencies": ["test/**"],
    "optionalDependencies": false,
    "peerDependencies": false
  }
],

Just list your tests folder in devDependencies instead of false.

我通过简单删除<代码>node_modules 加以解决。 然后进行<代码>npm安装

What I did to fix this:

"import/no-extraneous-dependencies": [
  "error",
  {
    "devDependencies": [
      "**/*.stories.*",
      "**/.storybook/**/*.*",
      "**/*.test.*"
    ],
    "peerDependencies": true
  }
]

For me, I finally figured out that the linter error was not happening when I ran yarn lint in the console and it was only VSCode that was erroneously highlighting my import statements with this error. Closing the project and re-opening in VSCode fixed the issue.

我也面临类似的问题,迄今为止,这些问题与在座的所有人不同解决。 我正在使用大体字体,而我的编造工作每次都使用大部分包件,而现在则有一包材料,显示<条码>进出口/无重大独立错误。

The key part of my .eslintrc:

  "settings": {
    "import/core-modules": ["dayjs"]
  }

Dayjs是给我这一错误的单元之一,但你可以添加任何模块,把错误带入核心模块,并解决问题。

我有这个问题,因为有些工具(很可能是“滚动”)产生了另一个<条码> 包装。 (含空的JSON{})载于我的项目分项下。 删除该档案有助于。

对我来说,在使用香蕉时,我有同样的问题:

为了解决问题,我指挥下:

yarn cache clean
rm -rf yarn.lock
rm -rf node_modules
yarn

最佳做法

上述解决办法都没有为我服务。 我正在着手实施另一个一揽子计划的项目。 json案在儿童名录中被nes。 这一错误出现在第二版目录中或该名录中的所有档案中。

变性:在含有其他包裹的儿童名录中填入lin子。 json案。

该项目我发现这一问题涉及进口组合,并要求()进口档案/包装。 我通过在座各位中增加共同点来解决这个问题。

  "env": {
    "browser": true,
    "es2021": true,
    "jest": true,
    "node": true,
    "commonjs": true
  },

任何人试图进口一个包件,先是“@”,例如“@aws-sdk/client-sqs”,对我来说,就是在每张import{SQSClient} from “@aws-sdk/client-sqs” ;。

我的问题是在安热器升级期间发生的。

编辑我的图书馆工作,但从我的图书馆进口时,午餐会留下错误:import/no-extraneous-dependencies

最终确定的是提升@typescript-eslint/eslint-plugin@typescript-eslint/parser

安星级更新了我的打字片版本,不再与这些图书馆兼容。

You can use the usePackageJson property to fix it, like this:

"import/no-extraneous-dependencies": [
  "error",
  {
    "devDependencies": false,
    "optionalDependencies": false,
    "peerDependencies": false,
    "usePackageJson": true
  }
]

我与大炮包有着类似的问题。 这对我来说是固定的。





相关问题
2. 先天: 模块外不得使用进口说明

我转而执行一个给我带来麻烦的A/RES/Server项目,因此,我认为我可以更新该项目,并在使用最新的Babel时遇到问题。 我的“指数”是:

不从事反应和 no

I m having issues with the proxy I set up. This is my root package.json file: "scripts": { "client": "cd client && yarn dev-server", "server": "nodemon server.js", "dev": "...

热门标签