使用express导入模块时出现问题,没有使用Bundler



我正在使用express构建一个应用程序,我不想使用捆绑器。当我导入axios模块时,它给了我下一个错误:&;Uncaught TypeError:未能解析模块说明符&;axios&;。相对引用必须以"/"、"/"或"…/";

到目前为止,我还在这里创建了整个项目的存储库:https://github.com/klaus4323/Natours-Nodejs.git我想使用axios的代码是在login.js(我正在做Jonas Schemetmann的nodejs在线类)文件:

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

export const login = async (email, password) =>{尝试{Const res = await axios({方法:"文章",url: http://127.0.0.1:3000/api/v1/用户/登录的,数据:{email,密码},});

如果(res.data。状态=== '成功'){showAlert('success', 'Logged in successfully ');window.setTimeout(() =比;{location.assign("/");5000);}Catch (err) {showAlert(‘错误’,err.response.data.message);}

};export const logout = async () =>{尝试{Const res = await axios({方法:"得到",url: http://127.0.0.1:3000/api/v1/用户/注销",});

如果(res.data。Status = 'success')) location.reload(true);Catch (err) {showAlert('error', '注销错误')。再试一次!");}

};

像这样使用从'axios'中导入* as axios

最新更新