DimiMikadze / create-react-library

React NPM library starter kit based on Facebook's create react app
MIT License
602 stars 60 forks source link

Support for the experimental syntax 'classProperties' isn't currently enabled #44

Closed SampsonCrowley closed 5 years ago

SampsonCrowley commented 5 years ago

this is something that is DEFINITELY in CRA

ideas?

./src/lib/components/modal-editor/modal-editor.js
SyntaxError: /home/samps/modules/react-component-templates/library/src/lib/components/modal-editor/modal-editor.js: Support for the experimental syntax 'classProperties' isn't currently enabled (9:20):

   7 |
   8 | export default class ModalEditor extends Component {
>  9 |   static propTypes = {
     |                    ^
  10 |     onClose: PropTypes.func.isRequired,
  11 |     changed: PropTypes.bool,
  12 |     heading: PropTypes.any,

Add @babel/plugin-proposal-class-properties (https://git.io/vb4SL) to the 'plugins' section of your Babel config to enable transformation.
hodgef commented 5 years ago

Hey @SampsonCrowley,

This is not supported by CRA v2 by default, since it's experimental syntax. https://github.com/facebook/create-react-app/issues/4648

However, I fixed this in my boilerplate since I needed this asap (https://github.com/hodgef/js-library-boilerplate)

Basically, add this to your package.json

"babel": {
    "presets": [
      "@babel/preset-env",
      "@babel/preset-react"
    ],
    "plugins": [
      [
        "@babel/plugin-proposal-class-properties"
      ]
    ]
  }

and this to your webpack.config.demo

loader: require.resolve('babel-loader'),
....
presets: [
    "@babel/preset-env",
    "@babel/preset-react"
],
plugins: [
    [
    "@babel/plugin-proposal-class-properties"
    ]
],

then run npm install

Regards

SampsonCrowley commented 5 years ago

@hodgef i can say with 100% certainty that is supported by v2 off the bat. I have not added anything to my babel config, or the plugins in my package.json for any of the CRA apps i'm currently building and they all work just fine with class properties

notice line 21 in babel preset react-app used by CRA: https://github.com/facebook/create-react-app/blob/master/packages/babel-preset-react-app/package.json

SampsonCrowley commented 5 years ago

@hodgef after rereading that thread I think I found the source of my confusion. application code does indeed have it enabled as I have verified, but library code specifically doesn't