Uncaught TypeError: Error resolving module specifier “axios”. Relative module specifiers must start with “./”, “../” or “/”

Viewed 271

I'm simply trying to import axios on the front end of my node.js project. and I am receiving the following error:

Uncaught TypeError: Error resolving module specifier “axios”. Relative module specifiers must start with “./”, “../” or “/”.

I am trying to import axios like so:

import axios from "axios";

I've tried using an axios CDN in my base.pug file, as well as using npm install axios.

here is my file structure: public/js/index.js <--- file that is trying to import axios views/base.pug <--- file with the CDN script tag

i also serve up my public file to the server from my app.js file:

app.use(express.static(path.join(__dirname, "public")));

I know i cant use the require method from the front-end:

const axios = require('axios');

I've also tried many different specifier combinations, although I shouldn't have do use those for axios.

0 Answers
Related