[英]Failed to load config "@ljharb" to extend from. (ESLint 8, Webpack 5)
I am in the process of upgrading packages for a project which uses Babel, Webpack, Eslint, and React.我正在为一个使用 Babel、Webpack、Eslint 和 React 的项目升级包。 In doing my package updates I am running into errors when rebuilding the application and could love to see what I am possibly missing from my configurations to generate the following error:
在进行我的包更新时,我在重建应用程序时遇到了错误,并且很想看看我的配置中可能缺少什么以生成以下错误:
ERROR in Failed to load config "@ljharb" to extend from.
Referenced from: C:\projects\project\node_modules\qs\.eslintrc
This project was originally using eslint-loader, but since that package is deprecated in favor of eslint-webpack-plugin and since I went from Webpack 4 to Webpack 5, I went through their documentation to update the config.js to reflect some new approaches.这个项目最初使用的是 eslint-loader,但由于该包已被弃用,取而代之的是 eslint-webpack-plugin,并且自从我从 Webpack 4 转到 Webpack 5 以来,我浏览了他们的文档以更新 config.js 以反映一些新方法. I believe I configured the options similar to the original implemented where eslint-loader was used, but I also do not believe this is the cause of my issues.
我相信我配置的选项类似于使用 eslint-loader 的原始实现,但我也不认为这是我出现问题的原因。 What I do see is that it seems like my node_modules are being linted.
我看到的是我的 node_modules 似乎被检查了。 I also know there are a lot of similar questions to this error, but most are around monorepo or nested node_modules, of which I have none and those solutions do not apply to this issue.
我也知道这个错误有很多类似的问题,但大多数都是围绕 monorepo 或嵌套的 node_modules,我没有这些问题,这些解决方案不适用于这个问题。
Steps I Have Taken I have done peer-dependency upgrades/installs for airbnb, which is where I believe this error originates.我已采取的步骤 我已经为 airbnb 完成了对等依赖升级/安装,我认为这是此错误的来源。 I have removed my node_modules, *-lock.json files, clean installs, and restarted VSCode and this error persists.
我已经删除了我的 node_modules、*-lock.json 文件、全新安装并重新启动了 VSCode,但此错误仍然存在。
Here are my configurations:这是我的配置:
package.json包.json
{
"name": "someProject",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"local": "webpack serve --env development",
"build": "webpack --env production",
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
"antd": "^4.18.2",
"aws-amplify": "^4.3.11",
"axios": "^0.24.0",
"bootstrap": "^5.1.3",
"connect-history-api-fallback": "^1.6.0",
"dotenv": "^10.0.0",
"express": "^4.17.2",
"formik": "^2.2.9",
"formik-antd": "^2.0.3",
"history": "^5.2.0",
"moment": "^2.29.1",
"react": "^17.0.2",
"react-bootstrap": "^2.1.0",
"react-cookie": "^4.1.1",
"react-dom": "^17.0.2",
"react-redux": "^7.2.6",
"react-router": "^5.2.0",
"react-router-dom": "^5.2.0",
"reactstrap": "^9.0.1",
"redux": "^4.1.2",
"url-loader": "^4.1.1",
"yup": "^0.32.11"
},
"devDependencies": {
"@babel/core": "^7.16.7",
"@babel/eslint-parser": "^7.16.5",
"@babel/plugin-transform-runtime": "^7.16.7",
"@babel/preset-env": "^7.16.7",
"@babel/preset-react": "^7.16.7",
"@babel/runtime": "^7.16.7",
"autoprefixer": "^10.4.1",
"babel-loader": "^8.2.3",
"babel-node": "0.0.1-security",
"clean-webpack-plugin": "^4.0.0",
"copy-webpack-plugin": "^10.2.0",
"css-loader": "^6.5.1",
"eslint": "^8.2.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.25.3",
"eslint-plugin-jsx-a11y": "^6.5.1",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-react": "^7.28.0",
"eslint-plugin-react-hooks": "^4.3.0",
"eslint-webpack-plugin": "^3.1.1",
"file-loader": "^6.2.0",
"html-loader": "^3.0.1",
"html-webpack-plugin": "^5.5.0",
"node-sass": "^7.0.1",
"nodemon": "^2.0.15",
"postcss-loader": "^6.2.1",
"precss": "^4.0.0",
"prettier": "^2.5.1",
"sass-loader": "^12.4.0",
"style-loader": "^3.3.1",
"terser-webpack-plugin": "^5.3.0",
"transform-runtime": "0.0.0",
"webpack": "^5.65.0",
"webpack-cli": "^4.9.1",
"webpack-dev-server": "^4.7.2"
},
"peerDependencies": {
"postcss": "^8.0.0"
},
"author": "",
"license": "ISC",
}
.eslintrc.json .eslintrc.json
{
"root": true,
"parser": "@babel/eslint-parser",
"parserOptions": {
"ecmaVersion": 2020,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
}
},
"settings": {
"react": {
"version": "detect"
},
"import/resolver": {
"node": {
"extensions": [".js", ".jsx", ".json"]
}
}
},
"extends": [
"airbnb",
"prettier"
],
"plugins": ["react", "react-hooks", "import", "jsx-a11y", "prettier"],
"env": {
"es6": true,
"node": true
},
"rules": {
"jsx-quotes": [
2,
"prefer-single"
],
"comma-dangle": 0,
"curly": [
2,
"all"
],
"arrow-body-style": [
2,
"always"
],
"camelcase": 0,
"class-methods-use-this": 0,
"consistent-return": 0,
"import/no-extraneous-dependencies": 0,
"import/no-useless-path-segments": 0,
"jsx-a11y/label-has-associated-control": 0,
"jsx-a11y/label-has-for": 0,
"jsx-a11y/no-noninteractive-element-to-interactive-role": 0,
"jsx-curly-spacing": 0,
"import/no-named-as-default": 0,
"import/no-named-as-default-member": 0,
"no-case-declarations": 0,
"no-console": 0,
"no-continue": 0,
"no-debugger": 0,
"no-lonely-if": 0,
"no-nested-ternary": 0,
"no-param-reassign": 0,
"no-plusplus": 0,
"no-restricted-globals": 0,
"no-trailing-spaces": 0,
"no-underscore-dangle": 0,
"no-unused-expressions": 0,
"no-unused-vars": 0,
"no-use-before-define": 0,
"operator-linebreak": 0,
"prefer-destructuring": 0,
"react/destructuring-assignment": 0,
"react/jsx-boolean-value": 0,
"react/jsx-curly-spacing": 0,
"react/jsx-filename-extension": 0,
"react/jsx-no-bind": 0,
"react/jsx-no-target-blank": 0,
"react/jsx-one-expression-per-line": 0,
"react/no-unused-state": 0,
"react/prefer-stateless-function": 0,
"react/prop-types": 0,
"react/react-in-jsx-scope": 0,
"react/sort-comp": 0,
"react/no-access-state-in-setstate": 0,
"template-curly-spacing": 0,
"no-will-update-set-state": 0,
"linebreak-style": [0, "error", "windows"]
},
"globals": {
"document": false
}
}
.eslintignore .eslintignore
**/node_modules/*
deploy/*
build/*
.ebextensions
.prettier*
**/test/**
.babelrc .babelrc
{
"plugins": [
[
"@babel/plugin-transform-runtime",
{
"regenerator": true
}
]
],
"presets": [
"@babel/preset-env",
"@babel/preset-react"
]
}
webpack.config.js webpack.config.js
const dotenv = require('dotenv');
const HtmlWebPackPlugin = require("html-webpack-plugin");
const path = require('path');
const webpack = require("webpack");
const ESLintPlugin = require('eslint-webpack-plugin');
const preCSS = require('precss');
const autoPrefixer = require('autoprefixer');
const APP_DIR = path.resolve(__dirname, "./src");
dotenv.config();
const ESLINT_PLUGIN_OPTIONS = {
extensions: ['js', 'jsx'],
exclude: [
'/node_modules/'
],
fix: false,
emitError: true,
emitWarning: true,
failOnError: true
};
module.exports = {
devServer: {
static: APP_DIR, // boolean | string | array, static file location
historyApiFallback: true,
},
entry: './src/index.js',
mode: 'development',
output: {
path: path.resolve(__dirname, 'build'),
publicPath: '/',
filename: 'main.js',
},
devtool: 'source-map',
module: {
rules: [
{
test: /\.(js)$/,
exclude: /node_modules/,
use: ['babel-loader'],
},
{
test: /\.html$/,
use: [
{
loader: "html-loader"
}
]
},
{
test: /\.(css|scss)$/,
use: [{
loader: 'style-loader', // inject CSS to page
}, {
loader: 'css-loader', // translates CSS into CommonJS modules
}, {
loader: 'postcss-loader', // Run post css actions
options: {
postcssOptions: {
plugins:
// post css plugins, can be exported to postcss.config.js
[
preCSS,
autoPrefixer
]
}
}
}, {
loader: 'sass-loader' // compiles Sass to CSS
}]
},
{
test: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/, /\.svg$/, /\.ttf$/, /\.pdf$/],
loader: 'url-loader',
options: {
limit: 100000,
name: 'static/media/[name].[hash:8].[ext]'
}
},
],
},
plugins: [
new ESLintPlugin(ESLINT_PLUGIN_OPTIONS),
new HtmlWebPackPlugin({
template: path.resolve("./src/index.html"),
filename: "./index.html"
}),
autoPrefixer,
],
resolve: {
alias: {
Assets: path.resolve(__dirname, 'src/assets/'),
Services: path.resolve(__dirname, 'src/services/'),
Styles: path.resolve(__dirname, 'src/styles/'),
Utilities: path.resolve(__dirname, 'src/utilities/'),
CommonComponents: path.resolve(__dirname, 'src/components/common/')
}
}
};
I know this issue resides in the webpack.config.js as changes in there are directly impacting the messages I see and no visible effect occurs within the other files being modified (eslintrc.json).我知道这个问题存在于 webpack.config.js 中,因为其中的更改直接影响我看到的消息,并且在其他正在修改的文件 (eslintrc.json) 中没有发生可见的影响。
Edit:编辑:
(In webpack.config.js) When I comment out the eslint-webpack-plugin and associated code, the bundle generates, so the error is 100% around the move from eslint-loader to eslint-webpack-plugin. (在 webpack.config.js 中)当我注释掉 eslint-webpack-plugin 和相关代码时,会生成包,因此在从 eslint-loader 到 eslint-webpack-plugin 的过程中,错误是 100%。 Is this a package version issue?
这是包版本问题吗?
I ran into the same problem and also tried a thousand solutions, including all of the variations of **/node_modules/**
in my.eslintignore file.我遇到了同样的问题并尝试了一千种解决方案,包括 my.eslintignore 文件中
**/node_modules/**
的所有变体。 What finally worked was changing it to the following:最终起作用的是将其更改为以下内容:
.eslintignore .eslintignore
/dist
/.quasar
/node_modules
.eslintrc.js
babel.config.js
package.json dev dependencies package.json 开发依赖
"devDependencies": {
"@babel/eslint-parser": "^7.13.14",
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.18.6",
"@babel/plugin-proposal-optional-chaining": "^7.18.9",
"@quasar/app": "^2.4.3",
"@quasar/quasar-app-extension-qcalendar": "^3.4.1",
"@quasar/quasar-app-extension-qiconpicker": "^1.4.3",
"@quasar/quasar-app-extension-qscroller": "^1.1.3",
"@vue/eslint-config-standard": "^4.0.0",
"eslint": "^8.10.0",
"eslint-config-standard": "^16.0.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-n": "^15.0.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^6.0.0",
"eslint-plugin-vue": "^9.0.0",
"eslint-webpack-plugin": "^2.0.0",
"mark.js": "^8.11.1",
"vue-clipboard2": "^0.3.1"
}
Also if you're using ESLint 7 you should be aware of this ESLint Github issue .此外,如果您使用的是 ESLint 7,您应该了解这个ESLint Github 问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.