[英]I have problem with install webpack react
这是错误
'React' is defined but never used
这是文件 app.js
import React from 'react';
这个文件 webpack.config.js
const path = require("path");
module.exports = {
context: __dirname,
entry: "./src/index.js",
output: {
path: path.resolve(__dirname, "dist"),
filename: "main.js",
publicPath: "/",
},
devServer: {
historyApiFallback: true,
},
module: {
rules: [
{
test: /\.js?$/,
exclude: /node_module/,
use: "babel-loader",
},
{
test: /\.css$/,
use: ["style-loader", "css-loader"],
},
{
test: /\.(png|j?g|svg|gif)?$/,
use: "file-loader",
},
],
},
plugins: [
new HtmlWebPackPlugin({
template: path.resolve(__dirname, "public/index.html"),
filename: "index.html",
}),
],
};
我在第 7 步有问题,我安装了 npm install eslint-plugin-react --save-dev 但无法解决这个问题。
澄清一下,这是您的 app.js 文件的全部内容吗?
import React from 'react';
或者您是否还编写了链接第 7 步中列出的 app.js 文件的 rest?
您看到的错误消息表明您已经导入了一个模块 (React),但您还没有将它用于任何事情。 如果import React from 'react';
是您的 app.js 文件的全部内容,那么这是可以预料的; 当您完成编写 app.js 文件时,此错误消息将 go 消失。
你走了一条需要大量手工工作的道路。 对于初学者甚至有经验的用户,我强烈推荐著名的 CRA 工具 ( create-react-app )。 它会为您设置一切,包括 Babel 和 Webpack。 当然,这取决于实际的 React 项目,但我发现这是一个很好的开始。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.