【发布时间】:2021-12-31 11:21:27
【问题描述】:
我正在使用 react.js 和 web pack。运行 NPM run build 命令时出现此错误,我正在学习如何使用 webpack 进行构建,所以我第一次尝试但收到此错误。请帮忙!
我从一些 webpack 教程网站编写了这段代码。
assets by status 1.05 KiB [cached] 2 assets
./src/index.js 796 bytes [built] [code generated] [1 error]
ERROR in ./src/index.js 13:2
Module parse failed: Unexpected token (13:2)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| const ProviderComponent = ()=>{
| return (
> <Provider store={store} >
| <App/>
| </Provider>
webpack 5.65.0 compiled with 1 error in 901 ms
npm ERR! code ELIFECYCLE
npm ERR! errno 1
网页包文件
const port = process.env.PORT || 8080;
const path = require('path');
const HtmlWebPackPlugin = require('html-webpack-plugin');
module.exports = {
output :{
path:path.join(__dirname,'/dist'),
filename:'main.[fullhash].js'
},
module:{
rules:[{
test:/\.(js|jsx)$/,
exclude:/node_modules/,
},
{
test: /\.less$/,
use: [
{ loader: 'style-loader' },
{ loader: 'css-loader' },
{ loader: 'less-loader' }
]
},
]
},
resolve:
{
mainFiles: ['index', 'Index'],
extensions: ['.js', '.jsx','.css'],
alias: {
'@': path.resolve(__dirname, 'src'),
}
},
plugins:[
new HtmlWebPackPlugin({
template:'./public/index.html'
})
],
devServer:{
host:'localhost',
port:port,
historyApiFallback:true,
open:true
}
}
【问题讨论】:
标签: reactjs webpack build bundle