【问题标题】:I have problem with install webpack react我有安装 webpack react 的问题
【发布时间】:2020-08-08 19:50:25
【问题描述】:

这是错误

'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

我在第7步遇到问题,我安装了 npm install eslint-plugin-react --save-dev 但无法解决这个问题。

【问题讨论】:

    标签: javascript reactjs webpack jsx eslint


    【解决方案1】:

    您走的路需要大量的手工工作。对于初学者甚至有经验的用户,我强烈推荐著名的 CRA 工具 (create-react-app)。它会为您设置好一切,包括 Babel 和 Webpack。当然这取决于实际的 React 项目,但我发现这是一个很好的开始。

    【讨论】:

      【解决方案2】:

      澄清一下,这是您的 app.js 文件的全部内容吗?

      import React from 'react';

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

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

      【讨论】:

        猜你喜欢
        • 2018-05-24
        • 2020-09-17
        • 2022-07-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-10-02
        • 2020-07-02
        • 1970-01-01
        相关资源
        最近更新 更多