Report this

What is the reason for this report?

How To Use Axios with JavaScript

Posted on May 6, 2021

After following the tutorial on building the To Do List, I am experiencing an error where the console is reporting: Uncaught SyntaxError:** import declarations may only appear at top level of a module**. The JS stops right there at the top, and no connection is made to the API. Everything else looks perfect…Can any on help with a clue?



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hello there.

This error usually means that there is a statement before an import. Imports must necessarily be before any kind of assignment or declaration.

I would recommend that you try adding type="module" to your script tag like this:

<script src="app.js" type="module"></script>

I hope that this helps. Let me know if it fixes your error.

Regards, Boyan

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.