nytimes / react-tracking

🎯 Declarative tracking for React apps.
https://open.nytimes.com/introducing-react-tracking-declarative-tracking-for-react-apps-2c76706bb79a
Other
1.88k stars 123 forks source link

Unable to run sandbox code #108

Open avinashhasule opened 5 years ago

avinashhasule commented 5 years ago

Hello , I tried same to execute code by downloading code from sandbox download link . While running exception gives Unexpected token @track.

tizmagik commented 5 years ago

Hi @avinashhasule you need to ensure you have your babel configured to transpile the decorator syntax. See here: https://github.com/loganfsmyth/babel-plugin-transform-decorators-legacy

tizmagik commented 5 years ago

Ah, I see what you mean now, just downloading the sandbox code and running it locally won't work because react-scripts (what create-react-app uses for its build configuration) doesn't support decorators. I'm honestly not entirely sure why it works in the web view of CodeSandbox but not when you download it, I think maybe they use TypeScript to compile or something?

Anyway, here's a few workarounds for developing locally:

Depend on decorators-react-scripts (instead of react-scripts), in package.json:

-    "react-scripts": "1.1.4",
+    "decorators-react-scripts": "2.1.3",

Or, use CRA via TypeScript, https://facebook.github.io/create-react-app/docs/adding-typescript (TypeScript can be configured to support @decorators)

Or, use craco to add decorators support to create-react-app without ejecting.

Or, eject from create-react-app and add the babel decorator plugin manually. I wouldn't recommend this approach if all you're adding are decorators.