【问题标题】:Problem importing module using express Not Using Bundler使用 express 导入模块时出现问题 不使用 Bundler
【发布时间】:2023-01-20 15:37:50
【问题描述】:

我正在使用 express 构建应用程序,我不想使用捆绑器。当我导入 axios 模块时,它给出了下一个错误:“未捕获的类型错误:无法解析模块说明符“axios”。相对引用必须以“/”、“./”或“../”开头。

到目前为止,我还在此处制作了整个项目的存储库:https://github.com/klaus4323/Natours-Nodejs.git 我想使用 axios 的代码在 login.js(我正在做 Jonas Schemetmann 的 nodejs 在线课程)文件中:

从“axios”导入 axios; 从'./alerts.js'导入{showAlert};

export const login = async (email, password) => { 尝试 { const res = await axios({ 方法:'POST', 网址:'http://127.0.0.1:3000/api/v1/users/login', 数据:{电子邮件,密码}, });

如果(res.data.status ==='成功'){ showAlert('登录成功', '登录成功'); window.setTimeout(() => { location.assign('/'); 5000); } 抓住(错误){ showAlert('错误', err.response.data.message); } };

export const logout = async () => { 尝试 { const res = await axios({ 方法:'获取', 网址:'http://127.0.0.1:3000/api/v1/users/logout', });

如果 ((res.data.status = '成功')) location.reload(true); 抓住(错误){ showAlert('error', '退出时出错。再试一次!'); } };

【问题讨论】:

    标签: node.js express axios


    【解决方案1】:

    像这样使用 从“axios”导入 * 作为 axios

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-02-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-19
      • 2018-03-21
      • 2011-02-19
      • 1970-01-01
      相关资源
      最近更新 更多