Standard cannot parse React JSX files
See original GitHub issueWhat version of this package are you using? 13.1.0
What operating system, Node.js, and npm version? Node v12 OSX (latest)
What happened? Take a simple react JSX file (from: https://reactjs.org/docs/hooks-intro.html)
import React, { useState } from 'react'
function IndexPage () {
const [count, setCount] = useState(0);
return (
<div>
<p>You clicked {count} times</p>
<button onClick={() => setCount(count + 1)}>
Click me
</button>
</div>
)
}
export default IndexPage
However, Standard cannot parse the file and thinks the {
is not valid JSX:
> standard
standard: Use JavaScript Standard Style (https://standardjs.com)
/Users/evan/workspace/evantahler.com/pages/index.js:8:22: Parsing error: Unexpected token {
This seems to be a new type of bug.
What did you expect to happen? Valid JS and Standard not to crash
Are you willing to submit a pull request to fix this bug? Sure!
Issue Analytics
- State:
- Created 4 years ago
- Comments:14 (8 by maintainers)
Top Results From Across the Web
Error when trying to run a test file on React component
I encountered this error when I tried running a unit test for my React component. I use VSCode so I notice ...
Read more >JSX In Depth - React
Fundamentally, JSX just provides syntactic sugar for the React.createElement(component, props ... JSX type can't be an expression. return <components[props.
Read more >How I resolved issues while setting up Jest and Enzyme in a ...
This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript. By default, if...
Read more >test suite failed to run jest encountered an unexpected token ...
Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is ......
Read more >babel/parser
Heavily based on acorn and acorn-jsx, thanks to the awesome work of @RReverser and @marijnh. API. babelParser.parse(code, [options]).
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@feross Yes! That’s great detective work.
I had an old version of Acorn in some projects, and I started re-installing deps 1-by-1 until it worked… and the working build lacks a top-level acorn requirement.
I’ll take your word for it 🤣