Parcel: Automatic JSX support for React doesnt work

Created on 8 Mar 2018  Β·  6Comments  Β·  Source: parcel-bundler/parcel

Choose one: is this a πŸ› bug report or πŸ™‹ feature request?
maybe bug or I missing something

πŸŽ› Configuration (.babelrc, package.json, cli command)

{
  "name": "learn",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "parcel-bundler": "^1.6.2"
  },
  "dependencies": {
    "react": "^16.2.0",
    "react-dom": "^16.2.0"
  }
}

πŸ€” Expected Behavior


run parcel and react with zero config

😯 Current Behavior

Automatic JSX support for React doesnt work without .babelrc ?

doesn't work

/Users/mmakmur/learn/src/app.jsx:5:9: Unexpected token (5:9)
  3 |
  4 | const App = () => {
> 5 |   return <p>hallo</p>;
    |          ^
  6 | };
  7 | ReactDom.render(<App />, document.getElementById("app"));
  8 |

πŸ’ Possible Solution

when I add .babelrc jsx parcel run with no error.

{
    "plugins": ["transform-react-jsx"]
  }

sould I use "transform-react-jsx" in .babelrc ?

πŸ”¦ Context

run parcel and react with zero config

πŸ’» Code Sample

🌍 Your Environment

| Software | Version(s) |
| ---------------- | ---------- |
| Parcel | v1.62
| Node | v9.5.0
| npm/Yarn | npm
| Operating System | mac

Bug

Most helpful comment

Works for me with:

<div id="app"></div>
<script src="./index.js"></script>
import React from 'react';
import ReactDom from 'react-dom';

const App = () => {
    return <p>hallo</p>;
};

ReactDom.render(<App />, document.getElementById("app"));

All 6 comments

Works for me with:

<div id="app"></div>
<script src="./index.js"></script>
import React from 'react';
import ReactDom from 'react-dom';

const App = () => {
    return <p>hallo</p>;
};

ReactDom.render(<App />, document.getElementById("app"));

@xabree Can you please fill out the β€˜Your Environment’ section of the issue template.

Also, it would be really useful if you can provide an example repo (or upload a zip) so we can try to reproduce the issue.

HI all thank for the response.

@mischnic the script is same with you , I think is not syntax error. but jsx is not automatically supported in my environtment maybe.

@davidnagli I Update environment

Without your code (maybe you can strip out as much code as you can), we can't help you.

This works: https://gist.github.com/mischnic/4a2c121c1074c7a9e5ec657db02637ac (no babelrc should be needed)

Also would be nice if you could run parcel -V to make sure you don't have a previous version installed globally

I'm sorry my mistake, I have already old parcel version installed globally.

@mischnic @DeMoorJasper Thank You. now parcel and react run with zero config :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dotdash picture dotdash  Β·  3Comments

donaldallen picture donaldallen  Β·  3Comments

adamreisnz picture adamreisnz  Β·  3Comments

466023746 picture 466023746  Β·  3Comments

algebraic-brain picture algebraic-brain  Β·  3Comments