Intended outcome:
I wanted to use the apollo-client library for grapqhl requests in my nativescript application.
Actual outcome:
The code failed, since no apollo-client was instanciated. After debugging, we found out that the code references the non existing variable process.env.NODE_ENV multiple times.
How to reproduce the issue:
Create a nativescript app and add the apollo client with version 2.5 and up.
Versions
Thanks for reporting this @000panther. This is likely being caused by Apollo Client's use of ts-invariant, which leverages process.env.NODE_ENV to help minifiers prune unreached code branches (to reduce bundle sizes). This isn't something we're likely going to change anytime soon, but are you using webpack for your builds? If so, maybe you could use DefinePlugin to create a process.env.NODE_ENV environment variable?
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': 'production'
}
});
We are using webpack, I will check if this workaround does the trick and report back on monday.
I believe this is something we can fix by polyfilling process in the ts-invariant package. It's definitely not a concern that anyone using the Apollo Client libraries should have to worry about. Sorry for the annoyance!
O.K we got it working. The snipped posted above did not work, I think because it used the wrong quotes and webpack inserted production without quotes in the packed code, and we got 'production not defined' errors.
working snippet:
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify('production')
},
}),
A colleague of mine (on iOS) also had some successes by installing the node-process npm package, but I could not reproduce this under android.
I think it would be great if apollo-client could work without such workarounds in browsers and environments like nativescript, and hope you can find a solution so that apollo-client works transparently for users in that environments.
Great, thanks for the follow up @000panther! We'll find a way to improve this.
Most helpful comment
I believe this is something we can fix by polyfilling
processin thets-invariantpackage. It's definitely not a concern that anyone using the Apollo Client libraries should have to worry about. Sorry for the annoyance!