3.5.2使用axios报错

coocs creator3.5.2,axios 0.27.2用不了
直接npm安装, 引入 import axios from 'axios/dist/axios.min.js'
报错

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’
报这个错:

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

把axios拷到assets目录下也一样报上面的错


简单使用 3.5.2 测试正常;
https://shrinktofit.github.io/can-i-use-npm-in-cocos-creator/

请问axios用的是哪个版本的?

把library、local、profiles等文件夹删了,重新运行可以了

意思是指直接用 3.5.2 打开的低版本项目后出现的?

不是,项目本来就是3.5.2创建的,至于怎么出现的我也不知道,一开始就是用npm引入的用不了,后来换复制axios也不行,然后把library、local、node_modules、profiles、temp等文件夹删了,重新打开项目运行就可以了

楼主解决了吗?我这里使用的 3.5.0 版本的也出现了这个错误,使用pnpm 安装的axios :sweat_smile:

之前做过一些总结,可以看看这个?

暂时想了一个解决 npm 包引入问题的临时方案 - Creator 3.x - Cocos中文社区

btw,cocos 不要用 pnpm,还是用 npm,cocos 无法支持 pnpm 的软链接,会找不到包

1赞

为了获取类型提示,将以下内容拷贝至任何 .d.ts 文件中,并在 tsconfig.json 中引用该 .d.ts 文件。

是如何引用的,我使用files引用没效果。

我也发现了。pnpm的问题

解决了吗 如何解决的