Question

How To Use Axios with JavaScript

Posted May 6, 2021 83 views
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?

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.

×
Submit an Answer
1 answer

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

  • Thanks Boyan, I really appreciate the feedback! Being a complete NOOB, I didn’t know about [ npm run dev ] so after adding the [ type=“module” ] attribute many other errors appeared because I hadn’t gone through the step of compiling everything and serving up the app with node. Yes, I was also just viewing the app in a regular browser window sans localhost:1234

    I just want to say this is a really great tutorial for anyone trying to learn JavaScript. It has opened a whole new frontier for me. The world of API’s is awesome 🤩. So much fun.