javascript - 无法加载配置“react”以从
问题描述
我正在尝试使用以下网站在不使用 create-react-app 的情况下创建一个反应应用程序:
但是,我不断收到这个错误,上面写着
./src/index.js 模块警告中的警告(来自 ./node_modules/eslint-loader/dist/cjs.js):无法加载配置“react”以扩展自。
我已经尝试安装所有依赖项并花了几个小时在谷歌上搜索答案,但我似乎无法找出问题所在。
这是我的 package.json:
{
"name": "xxx",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "webpack-dev-server --mode development",
"format": "prettier --write \"src/**/*.js\"",
"eslint-fix": "eslint --fix \"src/**/*.js\"",
"build": "webpack --mode production"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@babel/plugin-proposal-class-properties": "^7.10.4",
"react": "^16.13.1",
"react-bootstrap": "^1.3.0",
"react-dom": "^16.13.1"
},
"devDependencies": {
"@babel/core": "^7.11.6",
"@babel/preset-env": "^7.11.5",
"@babel/preset-react": "^7.10.4",
"babel-eslint": "^10.1.0",
"babel-loader": "^8.1.0",
"css-loader": "^4.3.0",
"eslint": "^7.9.0",
"eslint-config-react": "^1.1.7",
"eslint-loader": "^4.0.2",
"eslint-plugin-react": "^7.20.6",
"html-webpack-plugin": "^4.4.1",
"less": "^3.12.2",
"less-loader": "^7.0.1",
"prettier": "2.1.1",
"style-loader": "^1.2.1",
"webpack": "^4.44.1",
"webpack-cli": "^3.3.12",
"webpack-dev-server": "^3.11.0"
}
}
这是我的 webpack.config.js:
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
entry: './src/index.js',
output: {
// path: __dirname + '/dist',
path: path.resolve(__dirname, 'build'),
publicPath: '/',
filename: 'bundle.js'
},
devServer: {
contentBase: './build'
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: ['babel-loader', 'eslint-loader']
},
{
test: /\.less$/,
use: [
'style-loader',
'css-loader',
'less-loader',
],
}
]
},
plugins: [
new HtmlWebpackPlugin({
template: path.resolve('./index.html'),
})],
};
这是我的 .eslintrc:
{
"parser": "babel-eslint",
"extends": "react",
"env": {
"browser": true,
"node": true
},
"settings": {
"react": {
"version": "detect"
}
}
}
这是我的.babelrc:
{
"presets": [
"@babel/preset-env",
"@babel/preset-react"
],
"plugins": [
"@babel/plugin-proposal-class-properties"
]
}
有没有人有什么建议?我正在绞尽脑汁想弄清楚这一点,但我遇到了很多麻烦。它加载网页,但是根本没有使用反应。
先感谢您!!我真的很感谢你的帮助。
解决方案
I had a similar problem with create-react-app
and I did
yarn add eslint-config-react-app -D
I think you should try:
yarn add eslint-config-react -D
推荐阅读
- c - 在 C/C++ 中使用交错数据格式对复向量乘法进行向量化
- r - 在 highcharter R 图中设置字体
- linux - 我可以限制我的服务以 root 身份运行吗?
- javascript - 如何在 CKEditor 5 中禁用或删除填充?
- flutter - 如何根据背景更改文本颜色,以使两种颜色之间形成良好的对比
- javascript - WebStorm:动态生成的类方法的 JavaScript 代码完整
- git - 列出更改特定文件的提交?
- c++ - 在构造函数中复制静态数组
- javascript - javascript 引擎会优化闭包中定义的常量吗?
- java - 如何将来自后端的传入数据存储到周期性元素类型的数组对象中