Create-react-app: Production build breaks code that works in development

Created on 23 Jul 2016  路  14Comments  路  Source: facebook/create-react-app

import React from "react"

export default class App extends React.Component {
  render() {
    return (
      <div>
        <p>Parent</p>
        <AppItem />
      </div>
    )
  }
}

const AppItem = () => {
    return <div>child</div>
}

Works with npm start
Breaks with npm build, giving Element type is invalid error

If you rearrange the code so that AppItem is defined before App (or you use a hoisted function declaration) it works in both environments.

I suspect this has something to do with the react inline elements transformer?

bug underlying tools

Most helpful comment

I fixed this. babel/babel#3596

All 14 comments

@hzoo Does this look like a Babel bug to you? Worth filing an issue?

Yeah seems like it, can look at it later - looks like https://phabricator.babeljs.io/T6878, https://phabricator.babeljs.io/T7126

I can fix this.

I fixed this. babel/babel#3596

馃悎

PR merged. I guess this can be closed.

We pin versions so I鈥檇 like to leave it open for posterity until we pin to the version fixing this.

The fix is in a transitive dependecy so users will get the updated version regardless and you have no version to update as it's not a direct dependency.

We use bundledDependencies, I鈥檓 not sure whether this complicates the issue or not..

Seems like having to watch your deps more closely and releasing more often to get dep fixes out might be an implicit tradeoff for the single download and version stability from deduping and bundling _all_ your deps.

Just did a fresh install of react-scripts and got exactly what was bundled:

https://npmcdn.com/[email protected]/node_modules/babel-runtime/package.json

Released v6.12.0 with this fix https://github.com/babel/babel/releases/tag/v6.12.0 (and like @kittens said it's a fix in the babel-traverse pkg)

Thank you so much! I鈥檒l be using these for next release.
Since we can鈥檛 pin a transitive anyway (lol I don鈥檛 know npm), I鈥檓 closing.

This should be fixed in latest alpha. Please give it a try and let us know. https://github.com/facebookincubator/create-react-app/pull/190

Was this page helpful?
0 / 5 - 0 ratings

Related issues

stopachka picture stopachka  路  3Comments

ap13p picture ap13p  路  3Comments

rdamian3 picture rdamian3  路  3Comments

alleroux picture alleroux  路  3Comments

DaveLindberg picture DaveLindberg  路  3Comments