NativeScript with ApolloClient issue

333 views Asked by At

I created a standard app with tns create project --ng which ran fine (and adding platform android)

I also wanted to use graphQL so added apollo-client and graphql tag:

npm install apollo-client --save
npm install angular2-apollo --save
npm install graphql-tag --save

So now when I build with tns build android the error I get is...

node_modules/@types/isomorphic-fetch/index.d.ts(7,5): error TS2300:
Duplicate identifier '"audio"'.

which clashes with (from what I can see)

node_modules/tns-core-modules/declarations.d.ts(25,5): error TS2300:   
Duplicate identifier '"audio"'.

isomorphic-fetch is added when apollo-client was added. Not too sure about the typings issue but would be good to know how to get around this.

EDIT:

looking at the guide

I have the 2 items set to false in the tsconfig.json which seem to continue despite of the error...

    "noEmitHelpers": false,
    "noEmitOnError": false

But I would like to know how to fix this properly.

2

There are 2 answers

0
Camilo Azula On

Well I see tns-core-modules/declarations.d.ts is imported with tns-core-modules/tns-core-modules.base.d.ts so actually Nativescript should provide optionally one more definition where they dont include the request definitions in the base file

0
Keith Gillette On

I ran into the same issue but worked around it in a project with the following dependencies:

This requires changes to tsconfig.json and references.d.ts described in my response to Github nativescript-dev-typescript issue 19.

While this setup works in the browser with Angular CLI and builds for NativeScript using tns android without relaxing "noEmitOnError": true in tsconfig.json, I then had to debug a runtime exception with an apollo-client call to redux which attempts to call node.js code leading to the following error:

ReferenceError: process is not defined … /tns_modules/redux/lib/index.js', line: 38, column 4

This was worked-raound by adding global.process = { env: {} }; as the first line in main.ts, as described in NativeScript Github issue 2937, which StackOverflow won't allow me to link to due to my lack of reputation points.