Hello.
I would like to use axios but am having trouble with errors.
First, look at the official README and run the following command.
In my PC, axios is now installed.
Next, in Cocos Creator, I write the following code at the beginning of the class file to run the Example code.
import { _decorator, Component, Node } from 'cc';.
const { ccclass, property } = _decorator;
import axios from 'axios';
@ccclass('axiosTest')
export class axiosTest extends Component {
start() {
axios
.get('/user?ID=12345')
.then(function (response) {
// handle success
console.log(response);
})
.catch(function (error) {
// handle error
console.log(error); })
}); }
}
update(deltaTime: number) {}
}
This is perfectly fine in Visual Studio Code, but in reality it seems to cause an error and the script attached to the node is not recognized.
It is no problem up to “import axios from ‘axios’;”.
However, there seems to be a problem with axios in start that is causing the error.
I searched for axios on this forum for some information and found a topic created by cadxplore.
I rewrote the import based on pandamicro’s post, but this did not solve the problem.
import axios from 'axios';
↓↓
import axios from "axios/dist/axios.min.js";
Next, check the URL written by pandamicro.
Here is the topic created by tdf0495, where linrm presents the solution in RUL
However, the method described in this shrinktofit.github.io is written in Chinese, and I tried several translation services, but could not figure out what to change where.
It also looks different from the linrm error to begin with.
Any solution to this error would be appreciated!