I'm new to web development and I'm trying to incorporate node packages into my workflow. Specifically, I'm attempting to test out the axios ajax library.
It seemed like this would be a simple task, but it's proving to be quite challenging.
In my folder, I have an index.html and an index.js file.
I used "npm init -y" to create a package.json file and then installed axios with "npm install axios --save". The package is now in the node_modules folder and listed as a dependency in package.json.
Now, how do I actually use this library in my index.js file?
I tried the following in my index.js file (on the first line):
import axios from "axios";
When I check in Chrome, I get: "Uncaught SyntaxError: Unexpected identifier", and in Firefox: "SyntaxError: import declarations may only appear at top level of a module".
Even when I try linking the index.js file with type="module" (as suggested in other discussions), it still doesn't work and I receive different errors.
What am I missing here?