DEV Community

Bret
Bret

Posted on

what does this mean?: import { gql } from "@apollo/client"; ^^^^^^ SyntaxError: Cannot use import statement outside a module

I checked the way I’m using it, but what does this mean?:
‘’’

import { gql } from "@apollo/client";
^^^^^^
SyntaxError: Cannot use import statement outside a module

Top comments (7)

Collapse
 
faturachmanyusup profile image
Faturachman Yusup

Try to use require.

const { gql } = require('@apollo/client').

Or if you want it that way 'using import', you have to run it using npm start.

Hope it help. CMIIW.

Collapse
 
yobretyo profile image
Bret

So run “nodeman index”?

Collapse
 
faturachmanyusup profile image
Faturachman Yusup

import { gql } from '@apollo/client'

☝️npm start

const { gql } = require('@apollo/client’)

☝️ node index.js

Thread Thread
 
yobretyo profile image
Bret

THABK YOI!! Well, that error comes up when I try and add my ...coffeeMutation.Mutation

Then it throws that error

Thread Thread
 
yobretyo profile image
Bret

So, it’s running now.... but there’s still an error of a constructor

Thread Thread
 
faturachmanyusup profile image
Faturachman Yusup

if you don't mind, maybe you can share your repo link

Collapse
 
yobretyo profile image
Bret

Now it’s saying the same for “can’t find module react” .... what does that mean???