【问题标题】:dojo: multipleDefine error with qwest.jsdojo:使用 qwest.js 的 multipleDefine 错误
【发布时间】:2015-11-05 15:27:40
【问题描述】:

我正在尝试使用 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 配置对象中,但这样做会引发完全相同的错误。

配置:

  require({
    async: true
  , parseOnLoad: true
  , packages: [{
      name: `app`
    , location: `${location.pathname}js`
    , main: `main`
    }]
  }, [`app`])

【问题讨论】:

  • 请问您为什么要使用 Qwest ? Dojo 确实支持XmlHttpRequest2 特殊数据,例如ArrayBufferBlobFormData。 Dojo 也是基于Promise... 为什么不使用dojo/request 呢?
  • @ben 这不是一个特别好的理由,我之前的代码库中有一些 qwest 调用,但这成为关于 AMD 和multipleDefine 的更普遍的问题。我想我会尝试使用 vanilla Dojo(不是 ArcGIS 未缩小版)以便能够进一步调试。

标签: javascript dojo require amd arcgis-js-api


【解决方案1】:

我真的不知道您为什么会收到该错误,但您可以通过让 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>

【讨论】:

    猜你喜欢
    • 2016-09-03
    • 1970-01-01
    • 2018-04-22
    • 2018-04-11
    • 2014-10-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多