Yama
I’ve been trying to connect React to my Phoenix project but continue to get an error. The error says
Error in ./assets/js/app.jsx
Module build failed (from ./node_modules/babel-loader/lib/index.js);
SyntaxError: path -> app.jsx
const HelloReact = () => {
return <div>Hello World</div>;
}
error points to < in
I feel like this may be a babel problem. I decided to move package.json, webpack.config.js and .babelrc to the top level due to a recommended approach on a guide I was following. Was hoping to get a second look at eyes with how I’ve configured my React. Thank you for all the help.
My .babelrc looks like
{
"presets": ["@babel/preset-env", "@babel/preset-react"],
"plugins": ["@babel/plugin-proposal-class-properties", "@babel/plugin-proposal-object-rest-spread"]
}
As for my config file
module.exports = (env, options) => ({
optimization: {
minimizer: [
new UglifyJSPlugin({ cache: true parallel: true, sourceMap: false }),
new OptimizeCSSAssetsPlugin({})
]
},
entry: {
app: "./assets/js/app.jsx"
},
output: {
filename: "app.js",
path: path.resolve(__dirname, "priv/static/js")
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: {
loader: "babel-loader"
}
},
{
test: /\.css$/,
use: [MiniCSSExtractPlugin.loader, "css-loader"]
}
]
},
plugins: [
new MiniCssExtractPlugin({ filename: "../css/app.css"}),
new CopyWebpackPlugin([{ from: "assets/static/", to: "../" }])
],
resolve: {
extensions: ["*", ".js", ".jsx"]
}
});
Trending in Questions
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
Hello,
I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind.
However, when I launch mix phx.server, I get an error...
New
Hi everyone,
I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding.
I sta...
New
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
I’m working on a small exercise involving update_in/3, and I came up with this solution:
data = %{
name: "Periodic Table",
category:...
New
I’ve got trouble wrapping my head around the order in which functions are called in this snippet (from Phoenix’s authentication):
toke...
New
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
A little off-topic, but I feel like people here have a good head on their shoulders.
I used to be quite good at making software. Was luc...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ai
- #ecto-query
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #metaprogramming
- #hex










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
lucaong
Most likely a Babel problem indeed, as it seems it’s not transpiling JSX to JS.
The Babel configuration is always giving me headaches, and right now I am not really sure, but isn’t
babel.config.jssupposed to replace.babelrc? If I am right about that, yourbabel.config.jswill take precedence, and it does not include necessary presets like@babel/preset-react. That might be what causes JSX not to be transpiled.wolfiton
If you are new to react use the creat react app it works with npx and the guide can be found here.
https://facebook.github.io/create-react-app/docs/getting-started
Also this is very important https://reactjs.org/blog/2018/10/01/create-react-app-v2.html
kokolegorille
Is that your file?
I think You miss this…
Even if it is not visible, You need to import React before using this code
because it uses
React.createElement()under the hoodwolfiton
Also can you post your package.json file to see what packages you installed?
wolfiton
Also this tutorial should offer you a complete introduction to react and babel config the right way.
https://www.valentinog.com/blog/babel/
Yama
Hm I’ve been trying to look into
babel.config.jsand it doesn’t seem to be a requirement. I may be wrong but thank you for replying. Will continue to look about both files.Yama
Thank you for replying. Actually, it isn’t my first time using React but every time I try to use it for a project, the initial setup is usually a headache when it comes to webpack. Thank you for providing those linkes. I will take a look especially the tutorial I hope will point me in the right direction. As for the packages I installed, it’s
Yama
I apologize for not copying the code exactly as what I wrote. That is my part that has mislead you. The entire file looks like this
krstfk
I may be wrong, but isn’t the return block supposed to be wrapped with parens ie :
?
kokolegorille
Ok You do import React…
This is how I did for a babel 7.4.3 and React 16.8
I use a babel.config.js with this inside
I think I got this config on the babel site.
You may adapt for your usage.
In webpack.config.js, I have
BTW, as a minor note… I put react, react-dom in dependencies, and all @babel… in devDependencies