I have this working code.
define(['https://cdnjs.cloudflare.com/ajax/libs/axios/0.19.0/axios.min.js'],function(axios) {
axios.post('/user');
});
But I want to use axios inside next module r.js
define([
'https://cdnjs.cloudflare.com/ajax/libs/axios/0.19.0/axios.min.js',
'https://example.com/r.js], function(axios) {
return r;
});
But axios is undefined.
r.js
var r = function () {
console.log('worked') // worked
axios.post('/user'); // axios undefined
}
Is it possible? I have not access to requre.js config :-(
What your code is doing now:
axios
and r
,r
is regular script (not amd module) and does not have axios as dependencyr
loads first, then you have axios
undefinedaxios
loads first it registers itself as amd module and it is not visible as global, so you have undefinedFirst solution for your problem is to rewrite r
as amd module and specify axios
as its dependency.
Second solution is to specify axios
as r
's dependency via shim
.