我对安装webpack react有问题

问题描述 投票:0回答:1

这是错误

'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",
    }),
  ],
};

这是我学到的链接https://medium.com/@imranhsayed/set-up-react-app-with-webpack-webpack-dev-server-and-babel-from-scratch-df398174446d

我在step7中遇到问题,我告诉我npm install eslint-plugin-react --save-dev,但不能解决此问题。

javascript reactjs webpack jsx eslint
1个回答
0
投票

仅说明一下,这是您的全部app.js文件吗?

import React from 'react';

或者您是否还按照链接的第7步编写了app.js文件的其余部分?

您看到的错误消息表明您已经导入了模块(React),但尚未将其用于任何事情。如果import React from 'react';是app.js文件的全部内容,那么这是可以预期的;当您完成编写app.js文件时,此错误消息将消失。

© www.soinside.com 2019 - 2024. All rights reserved.