【问题标题】:Not able to run react project无法运行反应项目
【发布时间】:2019-07-07 13:56:00
【问题描述】:

我是 reactjs 的新手。我正在尝试编写 webpack。

const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
entry: './main.js',
output: {
  path: path.join(__dirname, '/bundle'),
  filename: 'index_bundle.js'
},
devServer: {
  inline: true,
  port: 3000
},
module: {
  rules: [
     {
        test: /\.jsx?$/,
        exclude: /node_modules/,
        loader: 'babel-loader',
        query: {
           presets: ['es2015', 'react']
        }
     },
     {
        test: /\.scss$/,
        use: [{
            loader: "style-loader"
        }, {
            loader: "css-loader"
        }, {
            loader: "sass-loader",
            options: {
                includePaths: ["absolute/path/a", "absolute/path/b"]
            }
        }]
     }
  ]
  },
  plugins:[
  new HtmlWebpackPlugin({
     template: './index.html'
  })
 ]
 }

HTML Webpack 插件: 错误:子编译失败: 找不到入口模块:错误:无法解析“F:\ react-app”中的“F:\react-app\index.html”: 错误:无法解析“F:\react-app”中的“F:\react-app\index.html”

  • compiler.js:141 [react-app]/[html-webpack-plugin]/lib/compiler.js:141:18

  • 编译器.js:306 [react-app]/[webpack]/lib/Compiler.js:306:11

  • 编译器.js:631 [react-app]/[webpack]/lib/Compiler.js:631:15

  • Hook.js:154 AsyncSeriesHook.lazyCompileHook [react-app]/[tapable]/lib/Hook.js:154:20

  • 编译器.js:628 [react-app]/[webpack]/lib/Compiler.js:628:31

  • Hook.js:154 AsyncSeriesHook.lazyCompileHook [react-app]/[tapable]/lib/Hook.js:154:20

  • Compilation.js:1325 [react-app]/[webpack]/lib/Compilation.js:1325:35

【问题讨论】:

    标签: reactjs webpack.config.js


    【解决方案1】:
    plugins:[
      new HtmlWebpackPlugin({
         hash:'true'
         template: './index.html'
      })
     ]
    

    将 hash 设置为 true 并确保模板文件的位置正确。

    【讨论】:

      猜你喜欢
      • 2017-09-30
      • 2021-03-27
      • 2021-06-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-30
      • 2021-06-15
      • 2022-06-30
      相关资源
      最近更新 更多