Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs bundle.js ERR_在使用webpack构建后中止404(未找到)_Reactjs_Webpack - Fatal编程技术网

Reactjs bundle.js ERR_在使用webpack构建后中止404(未找到)

Reactjs bundle.js ERR_在使用webpack构建后中止404(未找到),reactjs,webpack,Reactjs,Webpack,我曾尝试在服务器上启动我的项目,但当我打开页面时页面是白色的,在控制台中显示找不到budnle.js 我的文件夹结构如下所示: -dist -node_modules -public -src -client -server 我的webpack.config.js位于根文件夹中,如下所示 const path = require('path'); const HtmlWebpackPlugin = require('html-webpack-plugin'); const CleanW

我曾尝试在服务器上启动我的项目,但当我打开页面时页面是白色的,在控制台中显示找不到budnle.js

我的文件夹结构如下所示:

-dist
-node_modules
-public
-src
  -client
  -server
我的
webpack.config.js
位于根文件夹中,如下所示

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

const outputDirectory = 'dist';
var SRC = path.resolve(__dirname, 'src/client/assets');

module.exports = {
    entry: ['babel-polyfill', './src/client/index.js'],
    output: {
        path: path.join(__dirname, outputDirectory),
        filename: 'bundle.js'
    },
    module: {
        rules: [
            {
                test: /\.(js|jsx)$/,
                exclude: /node_modules/,
                use: {
                    loader: 'babel-loader',
                    query: {
                        presets: ['@babel/react',],
                        plugins: ['@babel/proposal-class-properties']
                    }
                }
            },
            {
                test: /\.(scss|css)$/,
                use: [
                    require.resolve('style-loader'),
                    {
                        loader: require.resolve('css-loader'),
                        options: {
                            importLoaders: 1,
                        },
                    },
                    {
                        loader: require.resolve('sass-loader'),
                    },
                    {
                        loader: require.resolve('postcss-loader'),
                        options: {
                            // Necessary for external CSS imports to work
                            // https://github.com/facebookincubator/create-react-app/issues/2677
                            ident: 'postcss',
                            plugins: () => [
                                require('postcss-flexbugs-fixes'),
                                autoprefixer({
                                    browsers: [
                                        '>1%',
                                        'last 4 versions',
                                        'Firefox ESR',
                                        'not ie < 9', // React doesn't support IE8 anyway
                                    ],
                                    flexbox: 'no-2009',
                                }),
                            ],
                        },
                    },
                ],
            },
            // Apply rule for images
            {
                test: /\.(png|jpe?g|gif|svg)$/,
                use: [
                    {
                        // Using file-loader for these files
                        loader: 'file-loader',

                        // In options we can set different things like format
                        // and directory to save
                        options: {
                            outputPath: 'fonts'
                        }
                    }
                ]
            },
            // Apply rule for audio
            {
                test: /\.(ogg|mp3|wav|mpe?g)$/i,
                include: SRC,
                use: 'file-loader'
            },
            {
                // Apply rule for fonts files
                test: /\.(woff|woff2|ttf|otf|eot)$/,
                use: [
                    {
                        // Using file-loader too
                        loader: 'file-loader',
                        options: {
                            outputPath: 'fonts'
                        }
                    }
                ]
            },
            {
                // Apply rule for video
                test: /\.(mov|mp4)$/,
                use: ['file-loader']
            }
        ]
    },
    resolve: {
        extensions: ['*', '.js', '.jsx']
    },
    devServer: {
        port: 3000,
        open: true,
        proxy: {
            '/api': 'http://localhost:5000'
        }
    },
    plugins: [
        new CleanWebpackPlugin([outputDirectory]),
        new HtmlWebpackPlugin({
            template: './public/index.html',
            favicon: './public/assets/img/favicon.png'
        })
    ]
const path=require('path');
const HtmlWebpackPlugin=require('html-webpack-plugin');
const CleanWebpackPlugin=require('clean-webpack-plugin');
const autoprefixer=require('autoprefixer');
const outputDirectory='dist';
var SRC=path.resolve(_dirname,'SRC/client/assets');
module.exports={
条目:['babel-polyfill','./src/client/index.js'],
输出:{
path:path.join(uuu dirname,outputDirectory),
文件名:“bundle.js”
},
模块:{
规则:[
{
测试:/\(js|jsx)$/,
排除:/node_模块/,
使用:{
加载器:“巴别塔加载器”,
查询:{
预设值:['@babel/react',],
插件:['@babel/proposal类属性']
}
}
},
{
测试:/\(scss | css)$/,
使用:[
require.resolve('style-loader'),
{
加载器:require.resolve('css-loader'),
选项:{
进口装载机:1,
},
},
{
加载器:require.resolve('sass-loader'),
},
{
加载器:require.resolve('postss-loader'),
选项:{
//外部CSS导入工作所必需的
// https://github.com/facebookincubator/create-react-app/issues/2677
标识:'邮政编码',
插件:()=>[
需要('PostSS-flexbugs-fixes'),
自动刷新器({
浏览器:[
'>1%',
“最后4个版本”,
“Firefox ESR”,
'不是ie<9',//React无论如何都不支持IE8
],
flexbox:‘no-2009’,
}),
],
},
},
],
},
//对图像应用规则
{
测试:/\(png | jpe?g | gif | svg)$/,
使用:[
{
//对这些文件使用文件加载器
加载器:“文件加载器”,
//在选项中,我们可以设置不同的内容,如格式
//和要保存的目录
选项:{
输出路径:“字体”
}
}
]
},
//对音频应用规则
{
测试:/\(ogg | mp3 | wav | mpe?g)$/i,
包括:SRC,
使用:“文件加载器”
},
{
//为字体文件应用规则
测试:/\(woff | woff2 | ttf | otf | eot)$/,
使用:[
{
//也使用文件加载器
加载器:“文件加载器”,
选项:{
输出路径:“字体”
}
}
]
},
{
//视频应用规则
测试:/\(mov | mp4)$/,
用法:[“文件加载器”]
}
]
},
决心:{
扩展:['*'、'.js'、'.jsx']
},
开发服务器:{
港口:3000,
开放:是的,
代理:{
“/api”:”http://localhost:5000'
}
},
插件:[
新的CleanWebPackagePlugin([outputDirectory]),
新HtmlWebpackPlugin({
模板:'./public/index.html',
favicon:“./public/assets/img/favicon.png”
})
]
})


知道我做错了什么吗?

请在index.html中查看bundle.js的路径,并查看它是否与dist文件夹中bundle.js的路径层次结构匹配。另外,请告诉我您是否可以从中单独下载bundle.jspath@Sunil我在底部有一行
,bundle.js在您的dist文件夹中的什么位置?请更新dist folder的文件夹结构,以便查看bundle.js的层次结构。index.html可能直接在dist文件夹下查找bundle.js,但您的代码可能正在某处创建bundle.jselse@Sunil有index.html和favicon.png