if you are only using babel to transform jsx to js, this is what you need :

installation

  • install babel-cli as global (optional) sudo npm install -g babel-cli
  • install babel-preset-es2015 (optional. if your code using es6 standard) npm install babel-preset-es2015
  • install babel-preset-react (required)

configuration

in your root of project, add this file .babelrc and write this to it

{
  "presets": ["es2015", "react"]
}

or

{
  "presets": ["react"]
}

run

babel source_dir -d target_dir
Answer from yussan on Stack Overflow
🌐
Reddit
reddit.com › r/reactjs › what’s the difference between .js & .jsx extension
r/reactjs on Reddit: What’s the difference between .js & .jsx extension
July 23, 2023 -

Hello everyone, I have been using .jsx this whole time when working with ReactJS but yesterday I thought of actually figuring out the difference and upon searching on internet it shows that creating html elements like (div, p, h1, etc) are convenient as the syntax is same and you’ve just put that inside “return”. But the same can be done inside .js, I was checking some code and saw devs using .js almost similar to .jsx and creating html inside it the same way it’s done in .jsx by putting things inside return statement.

Now at this point I am bit confused and really want someone to clarify the difference.

.jsx or .js for reactjs files? Aug 20, 2022
r/reactjs
4y ago
.jsx in browser May 2, 2025
r/react
last yr.
jsx or js file extension? Nov 21, 2022
r/reactjs
3y ago
JSX under the hood Dec 28, 2023
r/reactjs
2y ago
More results from reddit.com
🌐
React
legacy.reactjs.org › docs › introducing-jsx.html
Introducing JSX – React
These docs are old and won’t be updated. Go to react.dev for the new React docs. These new documentation pages teach modern React and include live examples: ... This funny tag syntax is neither a string nor HTML. It is called JSX, and it is a syntax extension to JavaScript.
🌐
Infoheap
infoheap.com › home › online tools › online lint
Online React jsx to javascript transformer using babel-cli - InfoHeap
Json syntax check · Online sass ... transformer · XML lint · Home · > Online Tools · > Online Lint · This online transformer can be used to compile react jsx to Javascript using babel-cli....
🌐
Transform
transform.tools › html-to-jsx
HTML to JSX
An online playground to convert HTML to JSX
🌐
Babel
babeljs.io › repl
Babel
Skip to main content
Top answer
1 of 4
16

if you are only using babel to transform jsx to js, this is what you need :

installation

  • install babel-cli as global (optional) sudo npm install -g babel-cli
  • install babel-preset-es2015 (optional. if your code using es6 standard) npm install babel-preset-es2015
  • install babel-preset-react (required)

configuration

in your root of project, add this file .babelrc and write this to it

{
  "presets": ["es2015", "react"]
}

or

{
  "presets": ["react"]
}

run

babel source_dir -d target_dir
2 of 4
4

As of 2023 if you are using babel to transform jsx to js, this is what you will need to do:

Install Packages

Install the following globally on your machine:

npm install -g @babel/cli
npm install -g @babel/core
npm install -g @babel/preset-react

or install the following as a project dependency (my personal preference):

npm install --save-dev @babel/cli
npm install --save-dev @babel/core
npm install --save-dev @babel/preset-react

Create Configuration File

Create a .babelrc config file at the root of your project with the following setting as a bare minimum:

{
    "presets": ["@babel/preset-react"]
}

You should review the babel docs if you have a more complicated use case and determine what additional settings you may need to add. You can find the settings for compiling jsx to js on the @babel/preset-react page.

Compile

You can compile any jsx file into js by running the following command in your terminal:

npx babel [jsx-file-here.jsx] -d [output-directory]

If your jsx file imports anything please keep the following in mind:

  1. This will not import any imported code. You will need to also compile any files that are imported. You can then use your code as a browser module: see next 2 points.
  2. JS imports are widely supported now (see also) but you will need to add type="module" to the script tag in your HTML.
  3. Remember you must include the file extension .js in your import statements still! No browser will intuptret import Foo from './bar' as import Foo from './bar.js.
  4. If you do not want to do the previous you can use something like rollup.js to bundle all the files into a single script.
Find elsewhere
🌐
DEV Community
dev.to › elpddev › converting-couple-thousands-jsts-files-that-contains-jsx-content-to-jsx-extension-58oh
Converting Extension from JS to JSX - DEV Community
May 26, 2024 - Without a transpiler in the process, ... in several ways. One of them is using a script to go though all project "js/ts" files, detect if they have any JSX syntax and change their extension....
🌐
TypeScript
typescriptlang.org › docs › handbook › jsx.html
TypeScript: Documentation - JSX
JSX is an embeddable XML-like syntax. It is meant to be transformed into valid JavaScript, though the semantics of that transformation are implementation-specific. JSX rose to popularity with the React framework, but has since seen other implementations as well.
🌐
React
legacy.reactjs.org › blog › 2020 › 09 › 22 › introducing-the-new-jsx-transform.html
Introducing the New JSX Transform – React Blog
September 22, 2020 - Since the new JSX transform doesn’t require React to be in scope, we’ve also prepared an automated script that will remove the unnecessary imports from your codebase. Create React App 4.0.0+ uses the new transform for compatible React versions. Next.js v9.5.3+ uses the new transform for compatible React versions.
🌐
DEV Community
dev.to › kashif_ullah_dev › how-react-jsx-gets-transformed-into-javascript-behind-the-scenes-467f
How React JSX Gets Transformed Into JavaScript Behind the Scenes - DEV Community
September 23, 2024 - Here's the magic: JSX is not valid JavaScript! Browsers can’t understand it directly. Behind the scenes, a tool like Babel steps in to convert (or "transpile") JSX into regular JavaScript.
🌐
BigBinary Academy
courses.bigbinaryacademy.com › learn-react › more-on-jsx › how-jsx-is-converted-to-js
How JSX is converted to JavaScript - Learn React | BigBinary Academy
Browsers don't understand JSX. It only understands HTML, CSS and JavaScript. Therefore, the code written in JSX needs to be converted to plain JavaScript. Babel is a toolchain that helps perform this conversion. Babel was introduced to help developers use new ECMA standard syntaxes without ...
🌐
React
react.dev › learn › writing-markup-with-jsx
Writing Markup with JSX – React
To return multiple elements from a component, wrap them with a single parent tag. ... This empty tag is called a Fragment. Fragments let you group things without leaving any trace in the browser HTML tree. ... JSX looks like HTML, but under the hood it is transformed into plain JavaScript objects.
🌐
Amnuts
blog.amnuts.com › 2016 › 07 › 13 › converting-jsx-to-js-on-the-command-line
Converting JSX to JS on the command line – Andy's blog o' goodness
July 22, 2016 - So now when I change a file in my jsx folder, such as components.jsx, it will create the equivalently name components.js file, correct transpiled and converted from JSX (and ES2015 arrow functions) to good ol’ javascript with ES5 bind methods.
🌐
Babel
babeljs.io › presets › @babel/preset-react › transform-react-jsx
@babel/plugin-transform-react-jsx · Babel
Decides which runtime to use. automatic auto imports the functions that JSX transpiles to.
🌐
Transform
transform.tools
Transform
to JSX · to Pug · to Big Query Schema · to Flow · to Go Bson · to Go Struct · to GraphQL · to io-ts · to Java · to JSDoc · to JSON Schema · to Kotlin · to MobX-State-Tree Model · to Mongoose Schema · to MySQL · to React PropTypes · to Rust Serde ·
🌐
Bitstack
blog.bitsrc.io › demystifying-jsx-building-your-own-jsx-parser-from-scratch-caecf58d7cbd
Demystifying JSX: building your own JSX parser from scratch | by Fernando Doglio | Bits and Pieces
March 4, 2025 - Because even inside the text nodes, we need to look out for JSX expressions inside {…} . So this function will take care of checking and properly changing the returned string if required. After that, meaning, we’re not really dealing with a Text Node, we’ll get the tag name (line 14), and we’ll parse the attributes (line 16). Parsing the attributes means we’ll take that raw string and turn it into a proper JSON.
🌐
GeeksforGeeks
geeksforgeeks.org › reactjs › what-is-the-difference-between-a-js-and-jsx-file-in-react
Difference Between a .js and .jsx File in React - GeeksforGeeks
July 23, 2025 - The .js file is a file that contains standard JavaScript code. These files do not contain the UI related code and are used for writing the logics and the functions. Used for regular JavaScript code and logic. Does not include JSX (HTML-like syntax). Can be used for utility functions, state management, or simple React components. No extra tools ...
🌐
YouTube
youtube.com › coding with jesse
Using React.js v0.12 - Part 8/8 - Convert JSX to JavaScript - YouTube
Warning: React v0.12 is now outdated. See how to upgrade to v0.14 here: https://www.youtube.com/watch?v=oiyCY5_qmQo To finish things up, I convert my JSX com...
Published: January 24, 2015
Views: 9K