我正在尝试使用dojo(ArcGIS)AMD加载器加载qwest.js
,但出现multipleDefine
错误。
require([
// `../vendor/react/react.js`, // this works fine
`../vendor/qwest/qwest.min.js`, // this causes error
], (
// React,
qwest,
) => { ... })
起初我以为是因为我将其作为软件包添加到了dojo config对象中,但是这样做会引发完全相同的错误。
配置:
require({
async: true
, parseOnLoad: true
, packages: [{
name: `app`
, location: `${location.pathname}js`
, main: `main`
}]
}, [`app`])
最佳答案
我真的不知道为什么会收到该错误,但是您可以通过让qwest
认为应该使用commonjs而不是amd来解决该错误:
//for testing purpose
require({
packages: [{ name: 'pyrsmk', location: 'https://rawgit.com/pyrsmk'}]
});
//the trick is to let qwest think you use commonjs instead of amd
window.module = {};
require(['pyrsmk/qwest/master/build/qwest.min'], function(qwest) {
qwest = module.exports;
delete window.module;
console.log(qwest);
});
<script src="https://rawgit.com/dojo/dojo/1.10/dojo.js"></script>