lourd / react-google-sheet

Pulling data from Google Sheets with React components
https://lourd.github.io/react-google-sheet
MIT License
24 stars 7 forks source link

[create-react-app] Failed to minify the code from a file #2

Closed ivorpad closed 6 years ago

ivorpad commented 6 years ago

I'm trying to include this module in a create-react-app app but I'm unable to do so.

Failed to minify the code from this file:

    ./node_modules/@lourd/react-google-sheet/dist/index.es.js:83
lourd commented 6 years ago

Hey @ivorpad, thanks for the bug report. Can you please make a repo I can clone that produces the error? Or post specific steps to reproduce it, including the version of CRA you're using. Thanks!

ivorpad commented 6 years ago

Hey @lourd,

Sorry I was short of time when I reported it.

Here it is: https://github.com/ivorpad/react-google-sheets-bug-report

Steps to reproduce:

create-react-app v1.3.0 (react-scripts v.1.1.4)

  1. yarn add @lourd/react-google-sheet
  2. import { GoogleSheet, GoogleSheetsApi } from '@lourd/react-google-sheet'
  3. yarn eject
  4. yarn buildFailed to compile.
lourd commented 6 years ago

Hi @ivorpad, sorry for the long delay in replying.

The root issue is that this module is being published with ES6 syntax and the version of Uglify that the current version of create-react-app is indirectly depending on cannot parse ES6.

There are 3 possible solutions I can think of:

  1. I could publish the code with only ES5 syntax. That's unfortunate because it means shipping more code.
  2. You could pre-transform the code and either move it into your application code or manage a fork.
  3. You could try using react-scripts@next, which is using webpack v4, which depends on the latest version of uglifyjs-webpack-plugin, which depends on a version of uglify-js that can parse ES6.

The steps to using the v2 beta version of create-react-app are:

create-react-app foo
cd foo
yarn add react-scripts@next

I found that even if you've installed create-react-app@next, you still have to manually upgrade react-scripts after generating the project.

Hope solution 2 or 3 suffices!

ivorpad commented 6 years ago

@lourd I moved to my own solution but thanks a lot for taking the time to reply. I'll keep your solutions in mind for the next project.