Answer the question
In order to leave comments, you need to log in
Why do React and Webpack throw an error when using JSX?
When run, it gives an error on the JSX syntax, here is my file:
import React from 'react';
import {render} from 'react-dom';
console.log(React);
function HelloWorld() {
return (
<div>
^
<h1>Hello World</h1>
</div>
)
}
render (<HelloWorld/>, document.getElementById('root'));
const path = require('path');
const PATHS = {
src: path.join(__dirname, '../src'),
dist: path.join(__dirname, '../dist'),
assets: 'assets/'
}
module.exports = {
externals: {
paths: PATHS
},
entry: {
app: PATHS.src
},
output: {
filename: `${PATHS.assets}js/[name].js`,
path: PATHS.dist,
publicPath: '/'
},
module: {
rules: [{
test: /\.js|jsx$/,
loader: 'babel-loader',
exclude: '/node-modules/'
},
Answer the question
In order to leave comments, you need to log in
plugins: @babel/plugin-transform-react-jsx
config like this
module: {
rules: [
{
test: /\.js|jsx$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env'],
plugins: [
"@babel/plugin-transform-react-jsx",
"@babel/plugin-proposal-class-properties"
]
}
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question