Question

How To Use Axios with JavaScript

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?


Submit an answer

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!

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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