googleanalytics / autotrack

Automatic and enhanced Google Analytics tracking for common user interactions on the web.
Other
4.93k stars 563 forks source link

Unexpected token operator #180

Closed marcogreselin closed 7 years ago

marcogreselin commented 7 years ago

Hello,

I'm building an app with create-react-app and after running npm run build I get the following error:

Creating an optimized production build...
Failed to compile.

static/js/main.e6cb3b60.js from UglifyJs
Unexpected token operator «=», expected punc «,» [./~/autotrack/lib/utilities.js:41,0][static/js/main.e6cb3b60.js:652,39]

I understand it's related to autotrack. I'm running the latest version.

philipwalton commented 7 years ago

This is because autotrack source code is published as ES2015, which uglifyjs doesn't currently understand. There's an open issue about this already, and it's not clear to me the best solution: https://github.com/googleanalytics/autotrack/issues/137

Either way, at the moment you can get around this issue by removing the import autotrack line from your JS file and instead loading autotrack directly from your page using a <script async> tag as explained in the usage documentation:

<script async src="path/to/autotrack.js"></script>