Error message: An import declaration can only be used in a namespace or module.

Hi, I am not a technical person at all and coding is not my industry. I am trying to add some code to my site so my welcome page transitions automatically after 10 seconds to my home page. I found that code online with many people saying that it worked for them. However when I tried to do the same… mine obviously bugged with 2 error messages:
For import “An import declaration can only be used in a namespace or module.”
and
For the location “Cannot find module ‘/wipwelcome’ or its corresponding type declarations.”

Any chance anyone can help (in a very simply way :joy: as I am no expert at all!)

Thanks in advance!

Romain

The import line must be at the top of your code (before the $w.onReady.

  • the path to the imported module is wrong.
    Is should be something like;
import wixLocation from 'wix-location;
setTitmeout(() => wixLocation.to('/may-page'), 10000);

Hi J.D. Thank you so much! The firt issue has been resolved!
However, it seems like I still do not insert the right path, location, link… the same errors still shows up. See the three screenshots below…
Any clue of what could fix this?

Thanks a million

change the import statement at the top to the following:

import wixLocation from "wix-location"

The wixLocation import is a part of the built in wix module. You only declare the page you want to navigate to when calling the wixLocation.to(). Not when originally importing wixLocation at the top of the page. Hope that helps :slight_smile:

Also here is the relevant velo docs: Introduction - Velo API Reference - Wix.com

1 Like

Sorted!!! Thank you so much!!! It made my day

thank you, i got it fixed (at last!)