3.1.2使用axios报错

你看,它说的是找不到 http 这个模块,那确实找不到啊,这个模块 Node 里面才有。你得用 axios 这个库不依赖 Node 的那个版本,你看它官网介绍哪个模块是为 WEB 用的。

1赞

明白了,谢谢

你是怎么成功的~~~ 是不是引用https://github.com/bundled-es-modules/axios这个ESM版本, 可是我还是引用不了~~~ :rofl:

import axio from "axio/dist/axios.min.js";
1赞

也不行。。。。

hi,你解决了吗?我也遇到同样的问题了…

可以试下flyio这个框架,支持npm安装

改用whatwg-fetch

引入了,但是使用时,提示很多包找不到,有使用demo吗

安装后进入node_modules目录找到flyio模块打开package.json, 将 “main”: “node-index.js” 修改成 “main”: “index.js” 就可以了,因为这个包默认导出的时node的http请求,改成index.js导出的时候就是browser模块了

解决了,感谢。

另外,看到很多友友,也遇到了跨域请求问题,分享一个跨域请求调试方法(仅仅开发阶段用,正式部署还是得同源或者用其他方案)

mac环境在控制台输入以下命令,禁用chrome的请求同源策略,就可以愉快的跨域请求联调:
open -na Google\ Chrome --args --user-data-dir=/tmp/temporary-chrome-profile-dir --disable-web-security --disable-site-isolation-trials

我遇到这个问题了,有解决方案没

目前用creator 3.x版本,用这个报错找不到模块,请问这个如何处理?
image

谢谢,解决了

请问如何解决的?

请问如何解决的?

进入node_modules目录,找到axios/dist/axios.min.js,复制到library目录下,然后用的时候导入即可,剩下的跟网页使用一模一样,import axios from ‘…/…/library/axios/axios.min.js’,我这个路径是因为在library目录下建一个文件夹叫axios

1赞

coocs creator3.5.2,axios v0.27.2用不了
报错

TypeError: __checkObsolete__ is not a function
    at Object.execute (c50adb79804ee01cfa4cf09c86b93d61ed6f4861.js:38:7)
    at doExec (system.js:444:34)
    at postOrderExec (system.js:440:12)
    at system.js:430:30
    at Array.forEach (<anonymous>)
    at postOrderExec (system.js:428:12)
    at system.js:430:30
    at Array.forEach (<anonymous>)
    at postOrderExec (system.js:428:12)
    at system.js:406:14

直接npm安装, 引入 import axios from 'axios/dist/axios.min.js'也是报这个错。
npm安装引入import axios from ‘axios’
报这个错:

Error: Unable to resolve bare specifier '__unresolved_5' from http://localhost:7456/scripting/x/chunks/c6/c6f1969f036e8d9d4d332fe596d233446b94550f.js (SystemJS Error#8 https://git.io/JvFET#8)
    at throwUnresolved (system.js:679:11)
    at SystemJS.systemJSPrototype.resolve (system.js:675:99)
    at SystemJS.systemJSPrototype.resolve (system.js:1020:24)
    at SystemJS.systemJSPrototype.resolve (system.js:1208:26)
    at system.js:336:39
    at Array.map (<anonymous>)
    at system.js:334:43
index.js:1 PromiseRejectionEvent {isTrusted: true, reason: Error: Unable to resolve bare specifier '__unresolved_7' from http://localhost:7456/scripting/x/chu…, type: 'unhandledrejection', target: Window, currentTarget: Window, …}
(anonymous) @ index.js:1
system.js:679 Uncaught (in promise) Error: Unable to resolve bare specifier '__unresolved_7' from http://localhost:7456/scripting/x/chunks/f4/f4bf496bbf55ef75f3092a3c0526b73aefbf9906.js (SystemJS Error#8 https://git.io/JvFET#8)
    at throwUnresolved (system.js:679:11)
    at SystemJS.systemJSPrototype.resolve (system.js:675:99)
    at SystemJS.systemJSPrototype.resolve (system.js:1020:24)
    at SystemJS.systemJSPrototype.resolve (system.js:1208:26)
    at system.js:336:39
    at Array.map (<anonymous>)
    at system.js:334:43
index.js:1 PromiseRejectionEvent {isTrusted: true, reason: Error: Unable to resolve bare specifier '__unresolved_4' from http://localhost:7456/scripting/x/chu…, type: 'unhandledrejection', target: Window, currentTarget: Window, …}
(anonymous) @ index.js:1
system.js:679 Uncaught (in promise) Error: Unable to resolve bare specifier '__unresolved_4' from http://localhost:7456/scripting/x/chunks/89/8978bd75d76636d037222c9d8c343ba48da3dc0c.js (SystemJS Error#8 https://git.io/JvFET#8)
    at throwUnresolved (system.js:679:11)
    at SystemJS.systemJSPrototype.resolve (system.js:675:99)
    at SystemJS.systemJSPrototype.resolve (system.js:1020:24)
    at SystemJS.systemJSPrototype.resolve (system.js:1208:26)
    at system.js:336:39
    at Array.map (<anonymous>)
    at system.js:334:43
index.js:1 PromiseRejectionEvent {isTrusted: true, reason: Error: Unable to resolve bare specifier '__unresolved_1' from http://localhost:7456/scripting/x/chu…, type: 'unhandledrejection', target: Window, currentTarget: Window, …}
(anonymous) @ index.js:1
system.js:679 Uncaught (in promise) Error: Unable to resolve bare specifier '__unresolved_1' from http://localhost:7456/scripting/x/chunks/45/45c1923a5a64a5d6f4f2f0bed16b52f5d8b74828.js (SystemJS Error#8 https://git.io/JvFET#8)
    at throwUnresolved (system.js:679:11)
    at SystemJS.systemJSPrototype.resolve (system.js:675:99)
    at SystemJS.systemJSPrototype.resolve (system.js:1020:24)
    at SystemJS.systemJSPrototype.resolve (system.js:1208:26)
    at system.js:336:39
    at Array.map (<anonymous>)
    at system.js:334:43
index.js:1 PromiseRejectionEvent {isTrusted: true, reason: Error: Unable to resolve bare specifier '__unresolved_4' from http://localhost:7456/scripting/x/chu…, type: 'unhandledrejection', target: Window, currentTarget: Window, …}
(anonymous) @ index.js:1
system.js:679 Uncaught (in promise) Error: Unable to resolve bare specifier '__unresolved_4' from http://localhost:7456/scripting/x/chunks/e8/e8bccfa5c86dcf16a6c21f8091ce6030eda98a2a.js (SystemJS Error#8 https://git.io/JvFET#8)
    at throwUnresolved (system.js:679:11)
    at SystemJS.systemJSPrototype.resolve (system.js:675:99)
    at SystemJS.systemJSPrototype.resolve (system.js:1020:24)
    at SystemJS.systemJSPrototype.resolve (system.js:1208:26)
    at system.js:336:39
    at Array.map (<anonymous>)
    at system.js:334:43
index.js:1 PromiseRejectionEvent {isTrusted: true, reason: Error: Unable to resolve bare specifier '__unresolved_2' from http://localhost:7456/scripting/x/chu…, type: 'unhandledrejection', target: Window, currentTarget: Window, …}
(anonymous) @ index.js:1
system.js:679 Uncaught (in promise) Error: Unable to resolve bare specifier '__unresolved_2' from http://localhost:7456/scripting/x/chunks/9d/9da12e344b07966501de2f4a313bb5c8cba3672f.js (SystemJS Error#8 https://git.io/JvFET#8)
    at throwUnresolved (system.js:679:11)
    at SystemJS.systemJSPrototype.resolve (system.js:675:99)
    at SystemJS.systemJSPrototype.resolve (system.js:1020:24)
    at SystemJS.systemJSPrototype.resolve (system.js:1208:26)
    at system.js:336:39
    at Array.map (<anonymous>)
    at system.js:334:43
index.js:1 PromiseRejectionEvent {isTrusted: true, reason: Error: Unable to resolve bare specifier '__unresolved_2' from http://localhost:7456/scripting/x/chu…, type: 'unhandledrejection', target: Window, currentTarget: Window, …}
(anonymous) @ index.js:1
system.js:679 Uncaught (in promise) Error: Unable to resolve bare specifier '__unresolved_2' from http://localhost:7456/scripting/x/chunks/b3/b3813b8c5a732c4a6269dd556d7b1ffc4cafa6be.js (SystemJS Error#8 https://git.io/JvFET#8)
    at throwUnresolved (system.js:679:11)
    at SystemJS.systemJSPrototype.resolve (system.js:675:99)
    at SystemJS.systemJSPrototype.resolve (system.js:1020:24)
    at SystemJS.systemJSPrototype.resolve (system.js:1208:26)
    at system.js:336:39
    at Array.map (<anonymous>)
    at system.js:334:43

方法不对,仔细看我的操作步骤

pnpm i -D axios安装
然后在node_modules的axios里找到dist,再找到axios.min.js
将它复制到项目的script里
用import axios from “./axios.min.js”;引入
测试:(亲测成功)
axios.get(‘https://api.vvhan.com/api/love?type=json’).then(data=>{

        console.log('data',data.data)

    })