0

Im building a application using express and I dont want to use a bundler. When I import the axios module it gives me the next error: "Uncaught TypeError: Failed to resolve module specifier "axios". Relative references must start with either "/", "./", or "../"."

I also made a repository of the entire project so far here: https://github.com/klaus4323/Natours-Nodejs.git The code where I want to use axios is in the login.js (I am doing the nodejs online class of Jonas Schemetmann) file:

import axios from 'axios'; import { showAlert } from './alerts.js';

export const login = async (email, password) => { try { const res = await axios({ method: 'POST', url: 'http://127.0.0.1:3000/api/v1/users/login', data: { email, password }, });

if (res.data.status === 'success') { showAlert('success', 'Logged in succesfully'); window.setTimeout(() => { location.assign('/'); 5000); } catch (err) { showAlert('error', err.response.data.message); } };

export const logout = async () => { try { const res = await axios({ method: 'GET', url: 'http://127.0.0.1:3000/api/v1/users/logout', });

if ((res.data.status = 'success')) location.reload(true); catch (err) { showAlert('error', 'Error logging out. Try Again!'); } };

1 Answer 1

0

Use like this import * as axios from 'axios'

Sign up to request clarification or add additional context in comments.

1 Comment

It did not work

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.