DEV Community

loading...

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

yobretyo profile image Bret ・1 min read

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

Discussion (7)

pic
Editor guide
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 Author

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 Author

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 Author

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 Author

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