gpt4 book ai didi

javascript - ReactJS模块构建失败: SyntaxError: Unexpected token - ReactDOM.渲染

转载 作者:行者123 更新时间:2023-12-03 13:06:19 24 4
gpt4 key购买 nike

为什么我会收到下面这个错误?我的声明ReactDOM.render(<App />, container);是 100% 合法的代码。

我的 github 存储库:https://github.com/leongaban/react_starwars

enter image description here

app.js 文件

import react from 'react'
import ReactDom from 'react-dom'
import App from 'components/App'

require('index.html');

// Create app
const container = document.getElementById('app-container');

// Render app
ReactDOM.render(<App />, container);

组件/应用程序文件

import React from 'react'

const App = () =>
<div className='container'>
<div className='row'>

</div>
<div className='row'>

</div>
</div>;

export default App;

我的 webpack.config

const webpack = require('webpack');
const path = require('path');

module.exports = {
entry: [
'./src/app.js'
],
output: {
path: path.resolve(__dirname, './build'),
filename: 'app.bundle.js',
},
module: {
loaders: [
{
test: /\.html$/,
loader: 'file-loader?name=[name].[ext]',
},
{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'babel-loader',
},
],
},
plugins: [
new webpack.NamedModulesPlugin(),
]
};

最佳答案

使用它作为你的 webpack 配置文件

const webpack = require('webpack');
const path = require('path');

module.exports = {
entry: [
'./src/app.js'
],
output: {
path: path.resolve(__dirname, './build'),
filename: 'app.bundle.js',
},
module: {
loaders: [
{
test: /\.html$/,
loader: 'file-loader?name=[name].[ext]',
},
{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'babel-loader',
query: {
presets: ['es2015', 'react']
}
},
],
},
plugins: [
new webpack.NamedModulesPlugin(),
]
};

您缺少预设

关于javascript - ReactJS模块构建失败: SyntaxError: Unexpected token - ReactDOM.渲染,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44267369/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com