question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Standard cannot parse React JSX files

See original GitHub issue

What 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:closed
  • Created 4 years ago
  • Comments:14 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
evantahlercommented, Aug 15, 2019

@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.

1reaction
mightyiamcommented, Aug 15, 2019

I’ll take your word for it 🤣

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found