Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Standard cannot parse React JSX files #1359

Closed
evantahler opened this issue Aug 14, 2019 · 7 comments

Comments

@evantahler
Copy link

commented Aug 14, 2019

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!

@evantahler evantahler changed the title Standard cannot parse React files Standard cannot parse React JSX files Aug 14, 2019

@feross

This comment has been minimized.

Copy link
Member

commented Aug 14, 2019

I cannot reproduce this issue. Indeed, the demo site shows it works just fine: https://standardjs.com/demo.html?gist=ff5832e447327defb72164f9e245bd4a

My guess is that you're pulling in an old version of standard (perhaps install globally?)

Can you share the output of these commands, run from your project folder:

  • standard --version
  • npx standard --version
  • npm ls standard

Thanks!

@evantahler

This comment has been minimized.

Copy link
Author

commented Aug 14, 2019

First off, that demo site using a Gist is awesome!

I created a small demo project that uses Next.JS, Jest and Standard... and it works fine. There must be something else in my main project getting in the way... sorry to bother you!

Example Project: https://github.com/evantahler/react-next-standard-test

@evantahler evantahler closed this Aug 14, 2019

@feross

This comment has been minimized.

Copy link
Member

commented Aug 15, 2019

Weirdly, I just ran into this issue on one my sites. Here's the build failure: https://travis-ci.org/feross/play.cash/builds/572130278?utm_source=github_status&utm_medium=notification

@evantahler Did you ever figure out the cause? Downgrading to standard@12 fixes the issue for me.

@feross

This comment has been minimized.

Copy link
Member

commented Aug 15, 2019

Oh sheesh, it's a bug in npm. Life is too short for this...

npm doesn't seem to install dependencies correctly if a package which has a name before eslint in the alphabet order and has old acorn in their dependencies list....

It looks like this is a workaround: rm -rf node_modules && npm install --legacy-bundling

Related issues:

@mightyiam

This comment has been minimized.

Copy link
Contributor

commented Aug 15, 2019

I'll take your word for it 🤣

@evantahler

This comment has been minimized.

Copy link
Author

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

ljharb added a commit to airbnb/react-dates that referenced this issue Aug 16, 2019

feross added a commit to feross/safe-buffer that referenced this issue Aug 19, 2019

@evantahler

This comment has been minimized.

Copy link
Author

commented Aug 22, 2019

It looks like for some projects, this is still a problem (see this upgrade and test suite) actionhero/www.actionherojs.com#63. npm install --legacy-bundling doesn't help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
3 participants
You can’t perform that action at this time.