"Cannot use import statement outside a module"

Hi, Prismic Support team!

I am implementing the Preview feature when content changes in Prismic.
So followed this instruction.

But I get a SyntaxError: Cannot use import statement outside a module

Please help me to solve this error.
Thanks,

Yurii

Hi Yuri,

I'll be happy to debug this with you, can you show me:

  1. your _document.js file
  2. you package.json

Thanks.

Please look at this image.
Thanks

Hi Yurri,

I'm guessing this is coming from the configuration of your project, maybe the linting or something, the following article explains how to fix it:

But essentially you'll need to import the file like this I guess:

<script type="module" src="next-slicezone/resolver"></script>

Let me know if this helps.

Thanks.

Well, then how can I use "createResolver" method there?

image

OK, it seems the workaround I suggested has made things worse.

What does your next.config.js file look like?

image

There is no importing 'createResolver' from the next-slicezone/resolver code in this instruction.
So I've removed it and I think it works well now.

Can you try updating your slicezone with

npm i next-slicezone@latest

and change your import back to

import { createResolver } from "next-slicezone/resolver";
1 Like

Yeah, it works as well!
Many thanks, Phil
:+1:

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.