JS driver and NativeScript + Angular

Hi, i just started learning faunadb and need help with the start. I’m using JS driver with typescript - NativeScript + Angular - so i import module like this

import * as fauna from 'faunadb';

Then i instantiated a client and tried to create a collection

   ` const client = new fauna.Client({ secret: 'fnAD2w2d7MACAVxxxxxxxxxxxxxxxxxxxxxxxxx' });
    const q = fauna.query;

    let createP = client.query(
        q.Create(
        q.Collection('test'),
        { data: { testField: 'testValue' } }
        )
    )
            
    createP.then(response => {
        console.log(response); // Logs the ref to the console.
    }) `

but an error occurs

` ERROR in …/node_modules/node-fetch/lib/index.mjs 1039:21-25
"export ‘default’ (imported as ‘http’) was not found in ‘http’
@ …/node_modules/cross-fetch/dist/node-ponyfill.js
@ …/node_modules/faunadb/src/Client.js
@ …/node_modules/faunadb/index.js
@ ./app/home/home.component.ts
@ ./app/home/home.module.ts
@ ./app/tabovi/tabovi-routing.module.ts
@ ./app/tabovi/tabovi.module.ts
@ ./app/app-routing.module.ts
@ ./app/app.module.ts
@ ./main.ts

ERROR in …/node_modules/node-fetch/lib/index.mjs 1406:56-60
"export ‘default’ (imported as ‘http’) was not found in ‘http’
@ …/node_modules/cross-fetch/dist/node-ponyfill.js
@ …/node_modules/faunadb/src/Client.js
@ …/node_modules/faunadb/index.js
@ ./app/home/home.component.ts
@ ./app/home/home.module.ts
@ ./app/tabovi/tabovi-routing.module.ts
@ ./app/tabovi/tabovi.module.ts
@ ./app/app-routing.module.ts
@ ./app/app.module.ts
@ ./main.ts `

Does anyone know what is wrong?

Hey, have you tried to just import like this : import fauna from 'faunadb'; ?
Or maybe deconstruct import { query as q, Client } from 'faunadb';
Because your code seems ok :slight_smile:

Yes but didn’t helped.
First, I was getting error with import faunadb
Import faunadb from faunadb
This wasnt working, error: faunadb/index has no default export so i was importing like this
Import * as faunadb from faunadb

Problem with importing Faunadb is solved but problems with node-fetch or cross-fetch and default exports are still present.
I changed import http in node-fetch/index.mjs
Import http from 'http' changed into Import * as http from 'http'
That solved errors but i cant connect to database
This const client = new faunadb.Client({ secret: 'fnAD2w2d7MACAVbxxxxxxxxxxxxxxxxxxxxxxxxx' });
throwing error:
ERROR TypeError: Cannot read property ‘env’ of undefined
:face_with_head_bandage:

I haven’t used NativeScript before, but my guess is that’s where the problem lies. It sounds like your code isn’t running in a “real” node environment, so there’s no guarantees that the standard libraries (like “http”) actually exist. I would guess that the fauna client hasn’t been written with these nonstandard environments in mind.