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:
axiosandr,ris regular script (not amd module) and does not have axios as dependencyrloads first, then you haveaxiosundefinedaxiosloads 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
ras amd module and specifyaxiosas its dependency.Second solution is to specify
axiosasr's dependency viashim.