Doesn't work with Create React App's build script
See original GitHub issueHi 👋
At the moment, analytics-node
doesn’t work with Create React App, as the build script fails when trying to minify the ES6 code (https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#npm-run-build-fails-to-minify). I’d like to hear if you’d be willing to publish a pre-compiled version?
I understand that this is a node library and perhaps not meant to be used in the browser, but the analytics.js
package on NPM is outdated, so please correct me if I’m wrong, but analytics-node
seems like the only way to use Segment if you want to load it through a module.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:14 (3 by maintainers)
Top Results From Across the Web
Create React App build does not work correctly - Stack Overflow
In localhost I can use and see everything correctly but when try it with npm run build , I can't reach anything and...
Read more >react-scripts fails to build project with Node 17 #11562 - GitHub
Describe the bug we have a CRA app, it used to build with Node 14.x very fine, today I upgrade nodejs to 17.0.0...
Read more >Deployment | Create React App
By default, Create React App produces a build assuming your app is hosted at the server root. This will let Create React App...
Read more >How to fix build failures with `create-react-app` in production
If your build is using create-react-app and has been failing since approximately the 18th of June 2020, this post will help you fix...
Read more >Everything you need to know about react-scripts
In this guide, we'll give an overview of react-scripts, compare a few different types of scripts, and describe how Create React App dramatically ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Please keep in mind that you are sort of comparing apples and oranges when comparing analytics-node in the browser to analytics.js and are giving up a lot of functionality.
analytics-node fits into this relatively tiny ~300 line file https://github.com/segmentio/analytics-node/blob/master/index.js
analytics.js by contrast looks like this for segment’s public facing site https://cdn.segment.com/analytics.js/v1/zaySL4FGIiLsxt3I7omU5uLxXqxaBMPh/analytics.js and packs in a lot more functionality than its analytics-node counterpart.
Edit: The following is instructions for create-react-app, client side rendering.
Hiyo @denkristoffer, the proper way to setup
analytics.js
in create-react-app is to put the script inside the<head>
element of your document; then load it with your Segment API key which is referenced through a custom environment variable:.env
file in the root of your project which contains your API key. Your.env
should look like this:analytics.js
snippet in the<head>
of yourpublic/index.html
and load the script using your API key which is referenced through custom environment variables:window.analytics
is loaded and available to use through your app 🎉 !