为什么浏览器环境的 js 无法调用 node_module 下的 axios 库

16次阅读

共计 365 个字符,预计需要花费 1 分钟才能阅读完成。

项目目录
–my_app
—-node_modules
——axios
—-index.html
—-main.js

index.html 代码:




    
    Title
    





main.js 代码:

import axios from "axios";

axios.get('http://localhost:5173/')
    .then(response => {console.log(response.data);
    })
    .catch(error => {console.error('Error:', error);
    });

浏览器 console 报错:

TypeError: Failed to resolve module specifier "axios". Relative references must start with either "/", "./", or "../".

搞不懂 …

正文完
 0